I have songs in iTunes on my MacBook pro that I have rated from one-start to five-star. When I open the songs in my DJ software, it doesn't show the ratings because iTunes doesn't write them to the ID3 tag, but just keeps it within iTunes.
I have figured out that I can read the rating by doing this:
tell application "iTunes"
set songRating to get rating of current track
end tell
return songRating
Also, I can get the location by doing this:
tell application "iTunes"
set songLocation to get location of current track
end tell
return songLocation
How do now use the file path that I have to write the rating into the ID3 tag of the file?
You could set the comment tag to the rating, that should be readable in a 3rd party app.
e.g,
tell application "iTunes"
set comment of the current track to "rating:" & (get rating of current track)
end tell
Ratings are percentage values, i.e, 2 stars == 40.
Related
I've been using an AppleScript to export photos in a Smart Album in Apple Photos for a while now. After upgrading to Catalina, it seems that my query for all albums no longer returns Smart Albums.
Specifically, I have a line that loads all albums like this:
tell Application Photos
set theseAlbums to every album
...
end tell
Previously, theseAlbums would contain regular and smart albums. After upgrading to Catalina, they only contain the regular (non-smart) ones.
Is there anything I can do to query for smart albums? I looked at the Photos Dictionary and didn't see anything. I also tried changing every album to every container with no luck.
Here's the code in context - a helper function that finds an album by name:
on getAlbumNamed(thisName)
tell application "Photos"
set theseAlbums to every album
repeat with i from 1 to the count of theseAlbums
set thisAlbum to item i of theseAlbums
if the name of thisAlbum is thisName then
return thisAlbum
end if
end repeat
end tell
end getAlbumNamed
Thanks in advance for any help.
I prefer to refresh my iTunes podcasts at times I control, so usually I right-click on the one I want to refresh, and choose Refresh Podcast. But sometimes I mistakenly select another menu item, and that's a real PITA. So I'd like to have an applescript which will only refresh a single podcast. I plan to hard-code the podcast into the script -- there's only one that I do near-daily, and the others can be done as and when I feel like it, with right-click. If I mess them up it's less of a PITA than with the main one.
The iTunes dictionary has updatePodcast and updateAllPodcasts -- clearly the former is the one I need to use (I don't want to have them all updated every time). But I can't figure out how to specify the podcast! The dictionary doesn't have a podcast class or anything similar, and item offers no obvious guidance either.
I've tried:
tell application "iTunes"
updatePodcast NameOfPodcast
end tell
Where NameOfPodcast is replaced by the exact string (AFAIK) that is in the iTunes podcast listing. Applescript tells me:
error "iTunes got an error: NameOfPodcast doesn’t understand the “updatePodcast” message." number -1708 from NameOfPodcast
Does anyone know how to get iTunes to refresh a single podcast from within applescript?
Edit:
Thanks to #user3439894 and #wp78de but referring to a track doesn't work. AS complains that the track doesn't understand the updatePodcast message. If I try to get a list of albums instead (every album of playlist "Podcasts" whose name is album_name), I get told that album is a property whereas it wants a class name.
Try it like this:
tell application "iTunes"
set allTracks to every track of playlist "Podcasts" whose album is "podcast_name"
repeat with singleTrack in allTracks
updatePodcast singleTrack
end repeat
end tell
Or try
tell application "iTunes"
updatePodcast (first track of playlist "Podcasts" whose album is "XY Podcast")
end tell
I know that there are many commands in AppleScript for Spotify such as the simple playpause command, but how would I pull a playlist's information from Spotify, and paste it in a choose from list? I would like it to take all of the songs from wherever you're listening from, and paste them in a choose from list so you can choose which song you would like to listen to. Is this even possible? Can I do something similar?
Also, how would you enable/disable shuffling?
Additionally, is there a way to search Spotify through AppleScript?
I'm not sure if any of these are possible, and Google doesn't have any info on this right now. Does anyone know how to do this?
The Spotify AppleScript implementation does not have specific commands to get at playlist information -- it only exposes "current track" to get info about the currently-playing track and "next track" to play the next track. You can work around this limitation to build an AppleScript array containing all the tracks in a current playlist.
set trackNameList to {}
set trackIDList to {}
tell application "Spotify"
activate
set shuffling to false
set repeating to true
set sound volume to 0
if player state is not playing then
playpause
end if
set trackID to spotify url of current track
repeat while trackIDList does not contain trackID
set end of trackIDList to trackID
set end of trackNameList to name of current track
next track
delay 1 -- otherwise Spotify misbehaves
set trackID to spotify url of current track
end repeat
end tell
tell me to activate
set chosenNames to choose from list trackNameList without multiple selections allowed
set chosenName to (item 1 of chosenNames) as string
repeat with i from 1 to count of trackNameList
set itsName to (item i of trackNameList) as string
if itsName is chosenName then
exit repeat
end if
end repeat
set trackID to (item i of trackIDList) as string
tell application "Spotify"
activate
set sound volume to 100
play track trackID
end tell
There is no AppleScript support for searching in Spotify.
I am using iTunes to convert a large .aif file to a much smaller .mp3 file. The filename changes each day because I am adding the date to the name. So, a file named "abcxyz 2-2-2014" gets converted in iTunes. After the conversion, I want to delete it from iTunes. I'm trying to use Applescript to search for the file and delete it. I'm trying this:
on deleteTrack(trackName)
tell application "iTunes"
set theTrack to track named trackName of playlist "Library"
set songFile to location of theTrack
delete theTrack
end tell
tell application "Finder" to delete songFile
end deleteTrack
on run
tell application "iTunes"
set result to (file tracks whose name contains "abcxyz")
repeat with t in result
deleteTrack(name of t as string)
end repeat
end tell
end run
I found the deleteTrack routine which works perfectly if you pass it a string like this:
on run
deleteTrack("abcxyz 2-2-2014")
end run
But that requires that I know the exact name of the track, which I don't. The error that I get is "Can't continue deleteTrack" ..with the deleteTrack(name of t as string) line selected in Applescript Editor.
Thanks for any help.
You should re-read the material about AppleScript's handlers. Because your handler call is inside of a tell application "iTunes" block, AppleScript is looking in iTunes for deleteTrack. Try this instead:
my deleteTrack(name of t as string)
I'm trying to run an Applescript that will play a song in iTunes. The problem is I need the song to have a specific artist as well. Whenever I write some script that uses "artist" I get an error stating that artist could not be accessed.
tell application "iTunes"
activate
play track "My Song"
end tell
this code works to play a track but I also need to specify the artist so that a track with the same name isn't accidentally played. Any help is greatly appreciated.
Thanks,
Sam
Adjust as necessary.
tell application "iTunes"
set mySongs to every track of library playlist 1 whose artist is "Styx" and name is "boat on the river"
repeat with aSong in mySongs
play aSong
end repeat
end tell