Can't fetch Smart Albums in AppleScript after upgrading to Catalina - applescript

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.

Related

Applescript code to refresh a single iTunes podcast

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

'A end of line can't go after this """' in this applescript

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

How to show all photos of an album using AppleScript

I am trying to put together an AppleScript to select each photo in my album. I have a smart album set up for my wedding and an iphone taking pictures. As the photos are taken, they are sent via iCloud photo stream to this smart album. I am using this script to make a slideshow of all the new photos coming in. (I want it to loop once it gets to the end of the photos.
I tried just making a slideshow, but it doesn't include new photos as they come in.
Here is my script so far. The error I am getting is that it cannot "Select" the photo.
set source_album to "wedding photos"
tell application "Photos"
activate
repeat until frontmost
end repeat
set photos to media items in album source_album
set selected_photo to selection
log selected_photo
repeat with i from 1 to count (photos)
set selected_photo to item i of photos
log selected_photo
select selected_photo --ERROR HERE!
delay 3
end repeat
end tell
Thanks for looking and helping!

Read Rating From ITunes, write it to file

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.

Search and delete a particular track in iTunes using Applescript

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)

Resources