I have a problem I can’t solve. I have Filemaker Pro 9 run a applescript to burn a CD with iTunes. I can’t figure out how to have the script wait for the CD to finish burning and eject the CD before continuing on with the script to delete the playlist I created. I guess I would also need to know if burn failed, if possible
In the final script I will get this_file and my_playlist name from a filemaker cell
the script I have so far is:
set this_file to “MacBook HD:Users:Kevin:Documents:allyn database stuff:savedaudio:kevin.aif”
tell application “iTunes”
activate
set my_playlist to make new playlist
set name of my_playlist to “AllynClientName”
tell my_playlist
add this_file to my_playlist
end tell
set artist of track 1 of my_playlist to “Allyn Miller,MFT”
set album of track 1 of my_playlist to “Meditation by Allyn Miller, MFT”
set genre of track 1 of my_playlist to “Meditation”
try
set view of front browser window to my_playlist
tell application “System Events”
tell process “iTunes”
click the menu item “Burn Playlist to Disc” of the menu “File” of menu bar 1
end tell
end tell
end try
delete my_playlist
delete (tracks of library playlist 1 whose artist is “Allyn Miller,MFT”)
end tell
thanks for any help
Model: MacBook
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
The next time you burn a CD, have Activity Monitor open to “All Processes” and sort it by CPU usage. You’ll see what process does the burning and you can ask System Events (in an idle handler) to check periodically for the name of that process. When it disappears, the CD is done, I’d imagine.
thanks for the input.
Before you replied I came up with the following solution by reading “Applescript” by Hanaan Rosenthal.
set dnme to playlist_name
tell application “System Events”
repeat until (name of disks contains dnme)
delay 3
end repeat
delay 10
tell application “Finder” to eject disk dnme
end tell
I did this since iTunes when done burning a an audio disc it gives it the name of the playlist
What do you think? will this script slow done the burning process?
Using a repeat loop may slow down the process, it depends on the horsepower of your Mac (and other programs running, etc.). The idle handler might be a better option. To use it, you must save your script as an application rather than a script and turn on the “Stay open” checkbox in the Save dialog. A for your use, the idle handler would look like this:
on idle
if (name of disks contains dnme) then tell application "Finder" to eject disk dnme
return 10
end idle
or you can set a different return time, this one uses 10 seconds. You don’t need to call the idle handler, the OS will do that for you every 10 seconds (in this example) or however often your return specifies.
One…
In trying to make the Filemaker database self-contained I wanted to be able to run the applescipt from within Filemaker. This is so if the database is moved to another machine the user doesn’t have to remember to copy the scrpt application too. I already have the database check on opening for folders I use to store backups and audio files and create the Folders (via applescript) if they don’t exist. If the best way is to use an idle handler in a stand alone scriptlet; is there a way to have Filemaker run a applescript that creates the scriptlet if it doesn’t exist?
Two…
In trying to make the process bullet proof as possible, how would I trap for a user who can’t find a blank CD that works and decides to cancel the burn in iTunes. I would want to know that so I could go on to delete the playlist and track from iTunes and go back to the Filemaker database
thanks again for all the great help
Kevin
Model: MacBook
Browser: Safari 419.3
Operating System: Mac OS X (10.4)
RE: Filemaker - You need a FM guru for that question, I don’t own it so I can’t answer that.
RE: Waiting for the CD to begin burning - If you know what the CD will be named, you can also watch in the idle handler for the appearance of the CD’s name in list of disks and then begin watching for the disappearance of it. If you don’t see the disk name appear in a reasonable amount of time, you can kill the script application or prompt the user with a dialog box.
I’d set a boolean global variable (or script property) called CDstarted or something and set it to true when the disk shows up in the list, then while that variable is true you can start checking for the CD name to drop out of the disk list in your idle handler.
Let me know how it goes, if you need more drop a line back here!