I have a Filemaker pro 7 database that stores the name of a specific song in iTunes in a text field. Is there a a applescript to get that field from Filemaker then open iTunes and select that song
I have not been able to find a solution anywhere
thank you in advance for any help
Model: iMac G4 and ibook G4
AppleScript: 1.10.3
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)
I don’t have File Maker, so don’t know how to get the data, but after you have the data, you can play a track. There’s no need to select a track. Say you have the name of a track:
tell application “iTunes”
set lib_pl to first library playlist
set track_name to name of some track of lib_pl
– now play the track with that name
set this_track to first track of lib_pl whose name is track_name
play this_track
end tell
The beginning part just gets a track name. The bad part is that there may be more than one track with the same name. You might want to get more info about the track from your database.
First thanks for the help.
Ok so I was able to get a song to play. If I know the playlist and the song how to I get that playlist to be selected so when you are looking at iTunes the playlist is selected so you can see the song being played in the window.
Thanks again for all the help.
Model: iMac G4 and ibook G4
AppleScript: 1.10.3
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)
Here’s an example using ui scripting. Your System Preferences must have "Enable access for assistive devices checked. This is needed to show the played track.
tell application “iTunes”
set pl_list to name of every playlist
end tell
set user_pl to choose from list pl_list
tell application “iTunes”
set pl_ref to first playlist whose name is user_pl
set track_list to name of every track of pl_ref
end tell
set user_track to choose from list track_list
tell application “iTunes”
activate
(* – to just select a playlist
set the_browser to first browser window
set view of the_browser to pl_ref – show the selected playlist
*)
set track_ref to first track of pl_ref whose name is user_track
play track_ref
end tell
tell application “System Events”
keystroke “l” using command down
end tell
Edited: one thing I should say is that the value returned by the ‘choose from list’ command is a one item list in this case. When getting the reference to playlist or track by its name, the list is coerced to string (the name). If the list were to contain more than one item, then this wouldn’t work and you would need to get the items (names) of the list first.
This will show the track of a playlist without selecting it.
tell application “iTunes”
set pl_list to name of every playlist
end tell
set user_pl to choose from list pl_list
tell application “iTunes”
set pl_ref to first playlist whose name is user_pl
set track_list to name of every track of pl_ref
end tell
set user_track to choose from list track_list
tell application “iTunes”
activate
set the_browser to first browser window
set view of the_browser to pl_ref – show the selected playlist
set track_ref to first track of pl_ref whose name is user_track
play track_ref
end tell
to show_current_track()
tell application “System Events”
tell application “iTunes” to activate
key code 37 using command down
end tell
end show_current_track
this is called after the track is playing. It works great. what do you think?
Also regarding making sure I am always storing the right song in my Filemaker database I saw this line in one of Doug’s scripts
set cur_tracks_id to cur_track’s database ID
Would storing the database ID in my Filemaker database make sure I always had the right song? could I use that in my itunes applescript to play the song with that database ID
thanks again
Model: iMac G4 and ibook G4
AppleScript: 1.10.3
Browser: Safari 417.9.2
Operating System: Mac OS X (10.4)
It’s almost the same except, I don’t think key codes are the same on all computers. You might want to check on that. The Command + “L” should be the same on all computers except non-English versions. The best would probably be to use the menu item number.
The database id is unique and a good choice. You would still need to get a reference to a track of a playlist, so something like this.
set track_ref to first track of playlist_ref whose database id is _whatever
because different playlists may have tracks with the same database id.