Ok...as for what was wrong with it:
1) The script ended before it began (when you have it return something, the script ends.)
2) you were trying to use Unix commands with ":" for a seperation instead of "/"
3) you weren't using "'" in case files names had more than one word. Example: ~/Desktop/song.zip works fine, however: ~/Desktop/song name.mp3 does not.
4) Tell active chat wasn't registering with Adium and returning an error, so I modified to ask from a list
Now, before you ask "WTF is all THAT!?"
Most of it is text manipulation.
Code: Select all
substitute()
on substitute()
-- Is iTunes playing?
tell application "System Events"
set iTunes to ((application processes whose (name is equal to "iTunes")) count)
--If iTunes isn't running, let them know
if iTunes is not greater than 0 then
display dialog "iTunes' not playing!" buttons {"Ok"} default button 1
else
-- you need an else here, otherwise it'll open iTunes
tell application "iTunes"
--If itunes is running but not playing, let them know
if player state is stopped then
display dialog "iTunes isn't playing!" buttons {"Ok"} default button 1
--otherwise If itunes is playing, continue the script
else if player state is not stopped then
set filepath to the location of the current track
set trackname to the name of the current track
if trackname is equal to "missing value" then
display dialog "No tune playing!" buttons {"Ok"} default button 1
end if
end if
end tell
end if
end tell
-- Zip It!
--set the contruction from applescript path ro unix path
set filepath to quoted form of POSIX path of filepath
--add "'"'s so that it's an executable command
set filepath to trim_line(filepath, "'", 0)
set filepath to trim_line(filepath, "/Users/admin", 0)
set j to replacesimple(filepath, "/", "'/'")
set j to replacesimple(j, "'/'Music", "~/'Music")
set filepath to j as string
set x to "ditto -c -k -X -rsrc " & filepath & " ~/Desktop/'" & trackname & "'.zip" as string
do shell script x
--Adium uses Applescript and therefore :'s unlike Unix's /'s
set deskpath to path to desktop as string
set tmppath to deskpath & trackname & ".zip" as string
-- Ok, now we send it!
tell application "Adium"
tell every chat
set mybuddies to ID
end tell
--There was an error with 'active chat' so I replaced it with choosing from list
set chosenbuddy to (choose from list mybuddies with prompt "Which buddy do you want to send '" & trackname & "' to?" without multiple selections allowed) as text
if chosenbuddy is not "false" then
send (first chat whose ID is chosenbuddy) file tmppath
end if
end tell
end substitute
on trim_line(this_text, trim_chars, trim_indicator)
-- 0 = beginning, 1 = end, 2 = both
set x to the length of the trim_chars
-- TRIM BEGINNING
if the trim_indicator is in {0, 2} then
repeat while this_text begins with the trim_chars
try
set this_text to characters (x + 1) thru -1 of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
-- TRIM ENDING
if the trim_indicator is in {1, 2} then
repeat while this_text ends with the trim_chars
try
set this_text to characters 1 thru -(x + 1) of this_text as string
on error
-- the text contains nothing but the trim characters
return ""
end try
end repeat
end if
return this_text
end trim_line
on replacesimple(thisText, oldChars, newChars)
-- version 1.1, Daniel A. Shockley http://www.danshockley.com
-- 1.1 coerces the newChars to a STRING, since other data types do not always coerce
-- (example, replacing "nine" with 9 as number replaces with "")
set oldDelims to AppleScript's text item delimiters
set AppleScript's text item delimiters to the oldChars
set the parsedList to every text item of thisText
set AppleScript's text item delimiters to the {(newChars as string)}
set the newText to the parsedList as string
set AppleScript's text item delimiters to oldDelims
return newText
end replacesimple
Not only does it compile, but it works. (i tested it)
As a side note, .zip compression really does nothing to .mp3s
the original file size is:
4741833 bytes or 5 MB
and the zipped file is:
4719440 bytes or 4.5 MB.
Enjoy!