The following script does not work as I expect:
tell application "iTunes"
tell source "Library"
tell playlist "Music"
set theTracks to (every track whose album artist is "xxx" and album is "Fiddle Tunes 2006 Concert")
count of theTracks
end tell
end tell
end tell
It matches tracks whose album artist property is empty. It should match no tracks. That particular album title has no tracks with a non-empty album artist field (and no tracks with the compilation flag set).
It I replace album artist with artist, it matches no tracks, which is correct.
Am I missing something obvious or is this a bug in iTunes?
It was a bug, fixed in macOS 10.12.5 and iTunes 12.6.1.25.
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 am writing an applescript to iterate thru all photo in the default album 'Photos'
Here is my script:
tell application "Photos"
activate
set alls = albums "Photos"
repeat with photo in alls
say photo.name
end repeat
end tell
Line 3. throws the following syntax error:
I am new to this language and I am unable to find an remedy to the incorrect syntax. Can any one point out what is amiss here?
If you refer to the dictionary it helps to understand how each element is contained by other elements. To get the photos of all albums you have to loop through the media items of every album. This will get the filename of each photo.
tell application "Photos"
activate
set alls to every album
repeat with photoAlbum in alls
set photos to every media item in photoAlbum
repeat with photo in photos
get filename of photo
end repeat
end repeat
end tell
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.
I'm writing an Applescript that displays a notification with the name, album, and artist of the current Spotify track. Yes, I'm aware there is already an app that does this, but even with the latest version, it's very buggy and behaves erratically.
So far, I have a good little script. Here it is:
repeat until application "Spotify" is not running
tell application "Spotify"
set theSong to name of current track
set theAlbum to album of current track
set theArtist to artist of current track
set theTime to player position
set theDuration to duration of current track
end tell
(* This sets the amount of delay to the length of the song minus the current place in the song, which leaves us with the amount of time left until the next song plays.*)
set delayTime to theDuration - theTime + 0.5
tell application "Spotify"
if player state is playing then
display notification theArtist with title theSong subtitle theAlbum
end if
delay delayTime
end tell
end repeat
Basically, the problem with this is if I pause or change the track, delay stays the same and thus doesn't display the notification when the song starts.
I used delay in this script because I don't really know a better way of checking for the end of a track. Is there any Applescript event for the end of a song (or the beginning of a new one?)
Thanks.
P.S., If this question is too complicated, feel free to ask more.
Use a loop to check the current track, exit the loop when the song change
repeat until application "Spotify" is not running
tell application "Spotify"
set theSong to name of current track
set theAlbum to album of current track
set theArtist to artist of current track
set thisTrack to current track
if player state is playing then
display notification theArtist with title theSong subtitle theAlbum
repeat until thisTrack is current track
delay 3
end repeat
end if
end tell
end repeat
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