AppleScript: open current iTunes track in another program [Riffstation] - applescript

I'm new to AppleScript and not programmer, so I'm hoping someone can help me out...
I want to get the current track path in iTunes and open the file in another program [Riffstation]
seems like this should work, but it doesn't:
tell application "iTunes"
set songLocation to get location of current track
end tell
tell application "Riffstation"
open songLocation
end tell
any help would be greatly appreciated!!!

Riffstation doesn't support AppleScript so you have to ask the Finder to open the file and pass it to Riffstation
tell application "iTunes"
set songLocation to get location of current track
end tell
tell application "Finder" to open songLocation using application file id "com.SonicLadder.Riffstation"
If you want to ignore .m4p files use
tell application "iTunes" to set {location:songLocation, kind:songKind} to current track
if songKind is not "Protected AAC audio file" then
tell application "Finder" to open songLocation using application file id "com.SonicLadder.Riffstation"
end if

Related

Can't set Desktop Background on Mac with AppleScript

I am trying to set the Desktop Wallpaper of my Mac(Running latest version of Catalina). But I keep getting this error message when trying to run my apple script.
error "System Events got an error: Can’t set file \"Library:Desktop Pictures:Ink Cloud.jpg:\" of current desktop to file \"Library:Desktop Pictures:Ink Cloud.jpg:\" of current desktop." number -10006 from file "Library:Desktop Pictures:Ink Cloud.jpg:" of current desktop
here is my code
tell application "System Events"
tell current desktop
set picture rotation to 0
set picture to file "Library:Desktop Pictures:Ink Cloud.jpg:"
end tell
end tell
I've been able to change all the other properties of the Desktop except the actual photo. I also tried using / for the file path. I have tried different file paths. But still not luck. Any help or advice would be greatly appreciated.
Running the code
tell application "System Events"
set currentPicturePath to picture of current desktop
end tell
reveals that the path is supposed to be a (slash separated) POSIX path
tell application "System Events"
tell current desktop
set picture rotation to 0
set picture to "/Library/Desktop Pictures/Ink Cloud.jpg"
end tell
end tell
Your (colon separated) HFS path contains two mistakes:
An HFS path (unlike the POSIX path) starts always with a disk name.
Only references to folders and packages have a trailing colon.

How can I open an MP3 with quicktime player using applescript?

I have the following code to open the files, but they all open with iTunes:
tell application "Finder"
set the_files to get every file of folder ("Macintosh
SSD:Users:myusername:Desktop:DJ:Music:Sort")
end tell
repeat with theItem in the_files
tell application "QuickTime Player"
open theItem
end tell
end repeat
Thanks!
AS syntax can be very misleading. While your open command is inside a tell application … end tell block, that doesn’t necessarily mean it will be sent to that application. If the command’s direct parameter happens to be a reference to objects in another app (in this case, a reference to a document file object in Finder) AS will send it to that app instead.
Use set the_files to get every file of folder (…) as alias list. That will get you a list of AppleScript alias values, instead of a list of Finder references (which any app other than Finder wouldn’t understand anyway).

Dynamic Slideshow using Applescript

I have a folder of images that gets updated from a camera taking pictures periodically throughout the day. I'm trying to write some applescript that will create a slideshow from a folder of images but also update as more are added without having to rerun the script. I started out trying to do quick look but couldn't get that working. Any ideas on how best to tackle this?
UPDATE
this is what I have hacked together so far:
tell application "Finder" to set the_folder to get folder (choose folder)
tell application "Finder" to open the_folder
tell application "System Events"
tell process "Finder"
key code 124
keystroke "a" using command down
keystroke " " using option down
end tell
end tell
I don't believe this works if I add photos behind the scenes though.
This is what I came up with and it works perfectly for what I need.
tell application "Finder" to set the_folder to get folder (choose folder)
tell application "Finder" to open the_folder
tell application "System Events"
tell process "Finder"
key code 124
keystroke "a" using command down
keystroke " " using option down
end tell
end tell
repeat while true
delay 60
tell application "System Events"
tell process "Finder"
keystroke "a" using command down
end tell
end tell
end repeat
A few caveats... since it is using quick look, you can't really do anything on the computer while this is running since it can't have any other app activate while it is running (quick look closes when this happens). Also the repeat section is required to get quick look to pickup the new additions to the directory without losing focus. Pretty nasty stuff, but I couldn't really find another easy way to do it!

AppleScript to launch and loop a video?

I need to write an AppleScript so that it will open QuickTime Player, play the movie from the specific file, and set it to loop in full screen. Help please I am a noob at writing AppleScripts.
This is what I have so far but it does not seem to work. :(
tell application "QuickTime Player"
open file "Macintosh HDN:Users:lalayana:Downloads:TV Master Keynote.m4v"
set the looping of movie 1 to true
play movie 1
end tell
The easiest way to do it is probably to assign the value returned by open file to a variable, and then tell that variable (that is, tell that movie) to do what it needs to do.
tell application "QuickTime Player"
set theMovie to open file "Macintosh HDN:Users:lalayana:Downloads:TV Master Keynote.m4v"
tell theMovie
set the presenting to true
set the looping to true
play
end tell
--use this to see what properties can be modified
--get the properties of theMovie
end tell
You can uncomment get the properties of theMovie to see what properties are available to modify.
If that doesn’t work for you, you’ll also need to specify exactly what you mean by “it does not seem to work”. That is, what error occurs, if an error occurs, or what happens differently than what you expect. I’ve verified that the above does work with a movie on my end.
I just had this problem and the solution above did not work for my apple computer, so I modified the script to get it to work. I wanted to the script to launch on boot, which I accomplished by going to System Preferences -> Users -> Login Items.
tell application "QuickTime Player"
set theMovie to open file "Users:danielmcclane:Downloads:startvideo.mov"
tell theMovie
set the looping of theMovie to true
set the present of theMovie to true
play
end tell
end tell
This worked for me. I use it to play video art pieces at the museum I work at. It works.
tell application "QuickTime Player"
activate
open alias "Users:ebowen:Desktop:MOUND_1.32GB_h264.mov"
play the front document
end tell
tell application "System Events" to tell process "QuickTime Player"
set frontmost to true
tell menu bar item 5 of menu bar 1
click menu item "Enter Full Screen" of menu 1
click menu item "Loop" of menu 1
end tell
end tell

How to set the file in rename mode in apple script?

I know this question is a little bit crazy, but I do want to know the solution. Is there any way to run an apple script to set any given file or folder in rename mode so that the user can type in the new name? I know I can do the rename easily in script but I am just wondering whether it is doable or not.
Thanks in advance!
Well, you can sort of hack it together with System Events
tell application "Finder"
activate
select file "test.png" of desktop
tell application "System Events" to keystroke return
end tell
It's kind of a hack, though, but I don't know if there's another way to do it
It is possible using UI scripting. First select whichever item you're interested in---presumably through AppleScript in practice, but by hand is fine for trying it out. Then:
tell application "Finder" to activate
tell application "System Events" to keystroke return

Resources