I have been reading these forums for a while and trying some stuff out, generally successful.
I have a question, I wrote a script to sync my iPod so that I can run it on schedule, as I am often in a rush for school the next morning. The only problem (a very small one) is getting it to Eject right when it is done.
I can use a “delay 10” command, but that would not work sometimes, as when my synchronize takes a bit longer than that.
So, I am asking if there is a way to detect when something is done and THEN do the next thing. I could, were I to need to, just make a very long “delay” command, but I was hoping there another way.
Thanks for any help, and here is an example of my very simple code;
tell application "iTunes"
repeat with s in sources
if (kind of s is iPod) then update s
end repeat
end tell
tell application "GrowlHelperApp"
set the allNotificationsList to ¬
{"iTunes"}
set the enabledNotificationsList to ¬
{"iTunes"}
register as application ¬
"Growl SQI" all notifications allNotificationsList ¬
default notifications enabledNotificationsList ¬
icon of application "iTunes"
notify with name ¬
"iTunes" title ¬
"iTunes" description ¬
"iTunes has successfuly synchronized!" application name "Growl SQI"
end tell
Model: MacBook4,1
AppleScript: 2.2
Browser: Firefox 3.5.2
Operating System: Mac OS X (10.5)
Caution: I am an applescript newbie. Use this script at your own risk
tell application "iTunes"
activate
tell application "System Events"
tell process "iTunes"
tell window 1
tell scroll area 1
if value of static text 1 is "iPod sync is complete." then
set theaction to my myaction()
end if
end tell
end tell
end tell
end tell
end tell
on myaction()
tell application "iTunes"
repeat with s in sources
if (kind of s is iPod) then eject s
end repeat
end tell
end myaction
Here’s an idea, although I’m not sure if it will work.
When you update an ipod presumably the free space on the disk will be changing because you are either writing files to it or removing files from it. So you could go into a repeat loop checking the free space on the disk. When the free space stops changing then presumably the update is finished… so something like this might work.
tell application "iTunes"
repeat with s in sources
if (kind of s is iPod) then
update s
set freeSpace to free space of s
repeat
delay 10 -- some arbitrary value
set currentFreeSpace to free space of s
if currentFreeSpace is equal to freeSpace then
exit repeat
else
set freeSpace to currentFreeSpace
end if
end repeat
end if
end repeat
end tell
Still does not seem to want to Eject right after. Thanks for the help, but I might just stick an Eject script on my iCal a half hour or so after the Sync script.