I have a number of movies in my iTunes 12.7.3.46 library on my Mac Mini. I have manually added album art to each video, but only about half the movies actually show the album art when viewing the movies from my AppleTV. The other half of the movies just show a frame. I double checked Get Info for the movies that aren't displayed the album art and confirmed that the album art is listed. Once I do this, the AppleTV will display the album art. I would like to write an applescript that I can run that will basically automatically do a "Get Info" for each movie so the art will display. Here is what I have so far:
tell application "iTunes"
set MovieList to tracks of playlist "Movies"
repeat with x from 1 to count of MovieList
tell (item x of MovieList)
refresh MovieList
end tell
end repeat
end tell
I saved the script here: /Library/iTunes/Scripts/Refresh.scpt
When I try to run this in iTunes (inside iTunes, there is a Scripts menu (an icon of a scroll, just left of Help), I get:
{«class cFlT» id 55680 of «class cUsP» id 55668 of «class cSrc» id 66 of application "iTunes", «class cFlT» id 56396 of «class cUsP» id 55668 of «class cSrc» id 66 of application "iTunes", «class cFlT» id 56395 of «class cUsP» id 55668 of «class cSrc» id
I don't even know what that means....any idea where to go from here?
This work for me using the latest version of Sierra
tell application "iTunes"
set theTracks to tracks of playlist "Movies"
repeat with i from 1 to number of items in theTracks
set this_item to item i of theTracks
try
refresh this_item
end try
end repeat
end tell
Related
I'd like an easy way to switch from a Spotify release to the same release in Apple Music.
I already found a way to search for the currently playing Spotify track in the Apple Music web player with Applescript:
tell application "Spotify"
if player state is not stopped then
set currentArtist to artist of current track as string
set currentTrack to name of current track as string
open location "https://music.apple.com/search?term=" & currentArtist & " " & currentTrack
end if
end tell
I'd love to:
Open the search in the native Music.app, not the web player. Is this supported?
Ideally not do a search, but go straight to the same release. Maybe with ISRC codes?
Take any selected Spotify track, not just the currently playing one. Looking at the Spotify Applescript dictionary tells me this in not possible.
had a similar problem right now and quickly hacked it out. In my case I want to simply trigger a search on the Music app.
Opened Automator and created a new "Service".
Workflow receives current > "Text" > in "every application".
Here's the AppleScript:
on run {input, parameters}
tell application "Music"
activate
end tell
tell application "System Events"
tell process "Music"
set window_name to name of front window
set value of text field 1 of UI element 1 of row 1 of outline 1 of splitter group 1 of window window_name to input
keystroke ""
key code 36
end tell
end tell
return input
end run
I saved it as "Find on Music" in Automator and now I can select text, right click > Service > Find on Music and Music plops open and shows me the results for the selected text. I hope you can use some parts of it.
I just figured out how to pass text from wherever to the search field in Music, with help from daemon's answer, which no longer works. This should work for what you want to do in conjunction with what you have.
Replace your "open location" line with a variable name for your concatenated string. Add this code below yours and pass that variable in place of 'input' (in my case 'input' is text from any application, which I use to select text of an artist name in an email/webpage/message that I want to send to Music's search).
First it checks to see if the main Music window is open vs the MiniPlayer, and open it if not to enable search via cmd-O, the cmd-F to find, then passes the input and hits return:
tell application "Music"
activate
end tell
tell application "System Events"
if not (exists (window "Music" of process "Music")) then
tell process "Music"
keystroke "0" using command down
end tell
end if
tell process "Music"
keystroke "f" using command down
keystroke input
key code 36
end tell
end tell
So, something like this (I don't have Spotify to check that section, but this should work assuming your code there is correct):
tell application "Spotify"
if player state is not stopped then
set currentArtist to artist of current track as string
set currentTrack to name of current track as string
set spotTrack to currentArtist & " " & currentTrack
end if
end tell
tell application "Music"
activate
end tell
tell application "System Events"
if not (exists (window "Music" of process "Music")) then
tell process "Music"
keystroke "0" using command down
end tell
end if
tell process "Music"
keystroke "f" using command down
keystroke spotTrack
key code 36
end tell
end tell
The only thing I couldn't figure out is how to check if the search field is already in focus, because if it is, the cmd-F causes a system alert sound. Generally not an issue as typically you'll search and interact with something else before running this script again, so calling it good. :)
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 wrote an Applescript that would monitor a folder for new input. On receiving the new item, it would open iTunes, create a playlist and add the new files into the playlist. However, when I attach the script as a Folder Action via Folder Action Setup and add a new item, nothing happens. I have placed the script inside /Library/Scripts/Folder Action Scripts as well as ~/Library/Scripts/Folder Action Scripts but it still doesn't fire. Here is my code below:
global album_name
global artist_album
on adding folder items to this_folder after receiving added_items
--get the name of the added folder
repeat with x in added_items
copy name of x as string to playlist_name
set AppleScript's text item delimeters to "-"
set delimited_playlist_name to every text item of playlist_name
set artist_name to text item 1 of delimited_playlist_name
set album_name to text item 2 of delimited_playlist_name
set AppleScript's text item delimeters to ""
end repeat
tell "Finder" to activate "iTunes"
tell application "iTunes"
if not (exists playlist album_name) then
--make iTunes playlist
make playlist with properties {name:album_name}
--add the tracks to the iTunes playlist
repeat with song in playlist_name
add song to playlist album_name
set album of song to album_name
set artist of song to artist_name
set comment of song to ""
set composer of song to ""
set grouping of song to ""
set description of song to ""
set long description of song to ""
set (volume adjustment) of song to 100
end repeat
set view of browser window to album_name
end if
end tell
end adding folder items to
I'm running Mac OS 10.8.4
In the future
Test your code in the Applescript Editor, it helps a lot :)
If you dont use Applescript Editor, to get useful messages, use display dialog entries throughout your code to see how far it goes and what is going on.
So, assuming that the problem is with your code, I rewrote it as an simple Applescript and got it to work on my Snow Leopard (10.6.8) system.
It also runs ok from inside Automator as a Folder Action with the code in a Run Applescript Action item. Once saved from inside Automator it did activate when new files were added to the folder and run ok.
PS: Since you didn't provide any details, I had to guesstimate from your code what you were trying to do. It is far from optimal but it will get you going...
HTH
# remove this line for Applscript Action in Automator...
set input to (choose file with multiple selections allowed)
set playlist_name to {}
#display dialog "Delimeter set to -"
set AppleScript's text item delimiters to "-"
repeat with x in input
#display dialog "Item: " & (x as text)
tell application "Finder"
set fl to name of x
display dialog "Filename: " & fl
end tell
# bring back focus to the editor ## TESTING ONLY
activate me
# append item to the list
copy (fl as text) to the end of playlist_name
display dialog "Playlist count: " & length of playlist_name
set artist_name to text item 1 of fl
display dialog "Artist: " & artist_name
set album_name to text item 2 of fl
display dialog "Album: " & album_name
end repeat
#display dialog "Activating iTunes..."
#activate "iTunes"
#display dialog "iTunes activated!"
tell application "iTunes"
if not (exists playlist album_name) then
display dialog "Making new playlist: " & album_name
make playlist with properties {name:album_name}
display dialog "Changing view..."
set view of browser window 1 to playlist album_name
# add the tracks to the iTunes playlist
repeat with song in input
display dialog "Adding: " & song
set newtrack to (add song to playlist album_name)
set album of newtrack to album_name
set artist of newtrack to artist_name
set comment of newtrack to ""
set composer of newtrack to ""
set grouping of newtrack to ""
set description of newtrack to ""
set long description of newtrack to ""
set (volume adjustment) of newtrack to 100
end repeat
else
display dialog "iTunes playlist already exists!"
end if
end tell
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
I have the code below to convert a track in iTunes but when it is trying to get the location of the converted track it errors:
tell application "iTunes"
set theFiles to the selection
repeat with theTrack in theFiles
with timeout of 120 seconds
set finish of theTrack to 30
set theSecondTrack to first item of {convert theTrack}
set theSecondPath to location of theSecondTrack
say "RingtoneDude has converted the song."
Error:
error "Can’t get location of {file track id 3942 of library playlist
id 2208 of source id 65 of application \"iTunes\"}." number -1728 from
«class pLoc» of {«class cFlT» id 3942 of «class cLiP» id 2208 of
«class cSrc» id 65}
Unfortunately you´ve misunderstood what location does. Revealing iTunes tracks in Finder is actually quite a bit more complicated but luckily has already been done by Doug Adams, as explained in this article.
You should definitely check out the rest of dougscripts.com as he has already created a script (for what I assume is your goal) called "make ringable" and released it under GNU GPL here
=== EDIT:
Oops, I´m sorry, looks like location does work, just not how I expected, try the following with one file selected:
tell application "iTunes"
tell item 1 of the selection to set theLocation to {get location}
tell application "Finder" to reveal theLocation
end tell