How Do You Get Applescript Editor To Shuffle All iTunes Songs? - applescript

How Do You Get Applescript To Shuffle All iTunes Songs?
This Part I've Found out:
tell application "iTunes"
activate
(...)
end tell

Access to shuffle has been removed as of iTunes 11. I suggest you look at this post: How to set iTunes 11 in shuffle or repeat mode via applescript

For iTunes 12 and Music x:
--> SET MODE TO SONGS, ALBUMS OR GROUPINGS
tell application "iTunes" to set shuffle mode to songs

Related

AppleScript plays playlist in Music.app on macOS Monterey

I'm working on this Alfred Workflow: https://github.com/gustavosaez/Alfred-Workflow-Apple-Music-Playlist
And today I'm looking for a day to "automate" the play music in background or hidden (to avoid open the application and click PLAY).
I found a way to set the mouse click on a screen position (specific on the play button), but it works only if the app is visible and if the resolution of screen is the same of mine.
I search about UI Elements for Music.app and didn't find anything.
The problem is:
When Alfred opens the chosen link, Music.app take a few seconds to open and load the playlist selected;
After this, space/play command is inactive, so I think to create a script that gets the current page and play the playlist in shuffle mode.
Any idea?
some ideas:
tell application "Music"
-- tell application "System Events" to tell process "Music" to click at {620, 374}
play current playlist
end tell
|
tell application "Music"
-- tell application "System Events" to tell process "Music" to click at {620, 374}
play {workflowPlaylistName}
end tell
tell application "System Events"
keystroke "h" using command down
end tell
I'm confused why you are trying to use mouse clicks or keystrokes, instead of just using
tell application "Music"
play
end tell
or
tell application "Music"
play the playlist named "{query}"
end tell
and pass the name of the playlist as query

How do you get the tracks of the Home Videos window in iTunes 11 with AppleScript

Not sure if I'm missing something, but my old go to in AppleScript for getting a selection of tracks seems to specifically NOT work on the new Movies > Home Videos view in iTunes 11.
tell application "iTunes"
get selection from browser window 1
end tell
Also tried below as implied here https://discussions.apple.com/thread/4576448?start=0&tstart=0
tell application "iTunes"
get selection
end tell
If I'm viewing the Home Videos collection, this returns {} regardless of what I have selected. If I switch to Movies > Movies and select some entries, this works as expected. Same if I'm viewing a playlist under Music.

Play iTunes Continously

I have an applescript that plays a specific iTunes playlist.
tell application "iTunes"
play user playlist myPlaylist
end tell
But this will only play the play list once, then it stops. What I want is for the playlist to reload, then play continuously 24/7 until someone actually stop or pause the iTunes.
I tried to modify the code to this, but it doesn't work.
on idle
tell application "iTunes"
play user playlist myPlaylist
end tell
end idle
The on idle code actually does nothing, even after iTunes stops.
I also try to reload the user playlist, but also doesn't work.
tell application "iTunes"
repeat until player state is stopped
play user playlist myPlaylist
end repeat
end tell
Thank you.
If you look in iTune's applescript dictionary at the "playlist" class you will see it has a command called "song repeat". Maybe that will help you.
tell application "iTunes"
tell user playlist myPlaylist
set song repeat to all
play
end tell
end tell
EDIT: As of itunes version 11 the above code no longer works. See this question for solutions. I posted an answer there.
The code for repeating playlist does not work on iTunes 11. The link regulusy6633 posted contains the answer. The code below works for iTunes 11.
tell application "System Events" to tell process "iTunes"'s menu bar 1's menu bar item "Controls"'s menu 1's menu item "Repeat"'s menu 1
perform action "AXPress" of menu item "All"
end tell

Remote AppleScript Events

I'm trying to open a QuickTime video on a remote computer but running into some issue.
Can someone help?
This is the code I've got so far, it's able to open the video but don't know how to get it to play...
set TheView2 to "eppc://username:password#TheView2.local"
set remoteFinder to application "Finder" of machine TheView2
using terms from application "Finder"
tell remoteFinder
open application file id "com.apple.QuickTimePlayer"
try
using terms from application "QuickTime Player"
tell application "QuickTime Player" of machine TheView2
open "Macintosh HD:Users:mini:Desktop:cache.mov"
end tell
end using terms from
on error errText number errNum
display dialog "Some other error: " & errNum & return & errText
end try
end tell
end using terms from
After you open the movie using the remote version of Quicktime just issue the "play" command in the same block of code. By the way, it is a bad idea to have nested tell blocks. Specifically in your case you have the Quicktime tell block inside the Finder tell block. Basically you're telling the Finder to tell Quicktime to do something. Why? The Finder doesn't need to issue any commands to Quicktime because applescript can do that itself. So separate the 2 tell blocks from each other. You'll have less conflicts that way.

AppleScript: How do I launch an application and then execute a menu command

I am trying to create a small applescript which will launch the DVD Player application and then resize it to its Actual Size. The code is listed below. When I run the code the DVD Player launches but it does not resize the window. What am I missing to get this to work?
Thanks,
Rob
do_menu("DVD Player", "View", "Actual Size")
on do_menu(app_name, menu_name, menu_item)
try
-- bring the target application to the front
tell application app_name
activate
end tell
delay 3
tell application "System Events"
tell process app_name
tell menu bar 1
tell menu bar item menu_name
tell menu menu_name
click menu item menu_item
end tell
end tell
end tell
end tell
end tell
return true
on error error_message
return false
end try
end do_menu
Have you looked at the dictionary for DVD Player?
There are properties for adjusting the size.
This will open it and go full screen:
tell application "DVD Player"
open
delay 2
set viewer full screen to true
end tell
Or there is the viewer size property which states:
viewer size (half/normal/double/max) : To set the the viewer size
So you could use this to go to Actual Size:
tell application "DVD Player"
open
delay 2
set viewer size to normal
end tell
Is that what you wanted to do?
I'm not in front of a Mac so I can't really test your code, but my suggestion is to try an existing and proven implementation of the same functionality, which uses recursion rather than nesting:
http://hints.macworld.com/article.php?story=20060921045743404
It's also possible that your delay 3 is not long enough for the DVD Player application to completely load before you start trying to script menu events. You could try debugging this by running two separate scripts and see if your menu-activation code works once the DVD Player app is loaded.

Resources