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

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

Related

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

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.

Using converted tracks in iTunes applescript

I have a script that iterates through tracks in a playlist. If they are already mp3 it adds them to my iPod (duplicate currentTrack to ipod_lib) and removes them from the playlist - this part works fine. If they are lossless however, I want to convert them to mp3 and add them to my iPod instead of add the lossless files themselves since they are too large. The line duplicate convertedTrack to ipod_lib throws the following error...
error "iTunes got an error: Can’t set library playlist id 270897 of source id 235166 to {file track id 322339 of library playlist id 38702 of source id 68}." number -10006 from library playlist id 270897 of source id 235166
the locateiPods code is pulled from a script on http://dougscripts.com/
Really not sure what I'm doing wrong here...
on locateiPods()
set the volumes_directory to "/Volumes/" as POSIX file as alias
set the volume_names to list folder volumes_directory without invisibles
set mounted_iPods to {}
repeat with i from 1 to the count of volume_names
try
set this_name to item i of volume_names
set this_disk to ("/Volumes/" & this_name & "/") as POSIX file as alias
set these_items to list folder this_disk
if "iPod_Control" is in these_items then
set the end of the mounted_iPods to this_disk
end if
end try
end repeat
-- check for iPod count
if the mounted_iPods is {} then
--
try
display dialog "iPod is not mounted." buttons {"Cancel"} with icon 0 giving up after 15
on error
error number -128
end try
else if the (count of the mounted_iPods) is greater than 1 then
-- choose iPod
set the ipod_names to {}
repeat with i from 1 to the count of the mounted_iPods
set this_iPod to item i of the mounted_iPods
tell application "Finder"
set the end of the ipod_names to the name of this_iPod
end tell
end repeat
tell application "iTunes"
activate
set this_name to (choose from list ipod_names with prompt "Pick the iPod to use:") as string
end tell
if this_name is "false" then error number -128
repeat with i from 1 to the count of the ipod_names
if item i of the ipod_names is this_name then
set this_iPod to item i of the mounted_iPods
exit repeat
end if
end repeat
else
set this_iPod to item 1 of the mounted_iPods
end if
return this_iPod
end locateiPods
tell application "iTunes"
set allTracks to every track in user playlist "TEST"
set the_iPod to my locateiPods() -- this is a path
set the_iPod_name to text 1 thru -2 of (the_iPod as string)
set ipod_src to some source whose name is the_iPod_name
set ipod_lib to library playlist 1 of ipod_src
repeat with i from 1 to count of allTracks
set currentTrack to item i of allTracks
set fileType to kind of currentTrack as string
if fileType is "MPEG audio file" then
duplicate currentTrack to ipod_lib
tell playlist "TEST" to delete contents of currentTrack
end if
if fileType is "Apple Lossless audio file" then
set convertedTrack to convert currentTrack
duplicate convertedTrack to ipod_lib
end if
end repeat
end tell
It seems doing the following makes it work, which suggests that convertedTrack is not of type track???
set convertedTrack to convert currentTrack
repeat with theTrack in convertedTrack
duplicate theTrack to ipod_lib
end repeat
I always used "convert" for list of tracks and then result is list of tracks. by the way it is much faster to convert list of tracks instead of doing loop to convert each track. May be you should do first a select of all tracks whose kind is lossless.
About convert, also keep in mind that convert does the conversion to the format set in your iTunes preferences. Then your scrip will depend of these preferences. I suggest, to be more safe, to save current preference, set the convert mode to format you want MP3, and then reset preferences to what they were before. You can use bellow script:
-- get & save current encoder
tell application "iTunes" to set Encoder_Base to name of current encoder
-- change encoder to MP3
tell application "iTunes" to set current encoder to (get first encoder whose name contains "MP3")
Also, may be you can optimise your iPod subroutine using Source method instead of looking for volumes mounted. iTunes kind of source provides an efficient way:
-- kind of source could be : library, iPod, audio CD, MP3 CD, radio tuner, shared library, iTunes Store
tell application "iTunes"
set myList to every source whose kind is iPod
if myList is {} then
display alert "no ipod connected"
return
else -- I assume if one iPod found, there is only 1 connected !!
set SourceName to name of first item of myList
set SourceID to id of first item of myList
end if
end tell
I hope it helps.

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!

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)

Append a variable to a link in AppleScript?

Currently I have this working code:
on run
set info to ""
tell application "System Events"
set num to count (every process whose name is "iTunes")
end tell
if num > 0 then
tell application "iTunes"
if player state is playing then
set albumName to (get album of current track)
end if
end tell
end if
return text 1 thru 10 of albumName
end run
if running iTunes and live albums are formatted correctly (YYYY-MM-DD) - this will bring back the date of a live album. I'd like to now take the result of "return text 1 thru 10 of albumName" and add it to this code:
tell application "Firefox" to activate
tell application "Firefox"
open location "http://someband.com/showID=" & *[insert code for "text 1 thr 10 of albumName" variable]*
end tell
I know the "&" isn't correct but I thought that was the start. The way this should work is if I'm listening to "2013-03-12 Live on StackOverflow" I want the script to take "2013-03-12" and append it to my link so Firefox opens website address: "http://someband.com/showID=2013-03-12"
...make sense? Any help would be greatly appreciated. Thank you!
Try:
if application "iTunes" is not running then return
tell application "iTunes"
if player state is playing then
set albumName to (get album of current track)
end if
end tell
set myText to text 1 thru 10 of albumName
-- Assuming Firefox is your default browser…
open location "http://someband.com/showID=" & myText

Resources