I’ve used Doug Adams’ “Current to Clipboard” for awhile and found it fairly useful…
but recently I wanted to be able to do more with the info it gathered.
The basic setUp:
I wanted to be able to upload a text file containing the current iTunes track info, so that I could provide that info on my personal website. I wanted to use Mr. Adams’ script without chopping it up… so I had to just work around it.
This is what I came up with:
on iTunesUpload()
-- in the version i run, I've included Mr. Adams' Script in this block.
-- snag clip info and write/replace iTunes txtfile
set trackInfo to "Macintosh HD:Users:CoffeeKid:Desktop:temp.txt"
set info to the clipboard as string
set trackText to open for access file trackInfo with write permission
set eof trackText to 0
write info to file trackInfo
close access trackText
tell application "URL Access Scripting"
-- path to file and ftp info -- user,pass,server
upload file trackInfo to "ftp://user:login@www.ftpserver.com" replacing yes without binhexing
end tell
end iTunesUpload
on run
iTunesUpload()
end run
on idle
iTunesUpload()
return 300
end idle
Please take a look, and post any comments, questions or concerns. I’d love to improve this, but my scripting skills as a bit weak.
I moved things around a little in the following script. The variable trackinfo only needs to be set once. So you can pull that out of the subroutine and make it a global variable or a property. Usually, you would pass the variable to the subroutine iTunesUpload() as a parameter, but it needs to be global for the idle handler anyway.
global trackInfo
on run
– initialize variables in the run handler or make them properties
set trackInfo to “Macintosh HD:Users:CoffeeKid:Desktop:temp.txt”
end run
on idle
iTunesUpload()
return 300
end idle
on iTunesUpload()
-- in the version i run, I've included Mr. Adams' Script in this block.
-- snag clip info and write/replace iTunes txtfile
set info to the clipboard as string
set trackText to open for access file trackInfo with write permission
set eof trackText to 0
write info to trackText -- faster to use the reference number (trackText) than the file reference
close access trackText
-- you might use an error handler here for error on uploading
tell application "URL Access Scripting"
-- path to file and ftp info -- user,pass,server
upload file trackInfo to "ftp://user:login@www.ftpserver.com" replacing yes without binhexing
end tell
Presumbably at some point, you will want your scripts to be portable – in other words to run on other people’s Macs.
The script you posted, and Kel tweaked for you, has the path to your desktop hard coded into the script. You might want to try something like this, so your script will work on other people’s computers:
set trackInfo to (path to “desk” as string) & “temp.txt”
It’s never too early to get into good script writing habits. I know, I cringe when I look at my first scripts…