Found out that I am able to control Spotify through terminal from here
http://www.instructables.com/id/RFID-Controls-for-Spotify-on-OSX-using-hacked-Mir/?ALLSTEPS
for example skipping to the next song, you would type this in the terminal:
osascript -e 'tell application "Spotify" to next track'
Just wanted to know if there was a way to create a new playlist on Spotify through the terminal .
Cheers.
No, creating playlists it's not possible using the desktop application's API.
Some useful resources:
The API reference can be found at /Applications/Spotify.app/Contents/Resources/Spotify.sdef
A shorter guide can be found at https://developer.spotify.com/applescript-api/
Related
is there a way to run a simple tell application quit, when a specific application is opened.
For example, if I open spotify, is there away to trigger a script to quit the app.
Thanks!
is there a way to run a simple tell application quit, when a specific application is opened.
Short Answer: Yes
Longer Answer:
Here are a couple of ways that come to mind...
There is a paid application called EventsScripts that among the many events it can react to, one category is Application Events which contains, Application activated, Application deactivated, Application will launch, Application launched and Application quit.
EventsScripts works with both AppleScript scripts and shell scripts.
Have a look at EventScripts. At the time of this post, it's $5.99 at the US App Store, but a free demo is downloadable from the developers website.
Note: I am not affiliated with the developer of EventScripts, just a satisfied user of the product.
Example AppleScript code:
on run eventArgs
set thisTrigger to (trigger of eventArgs)
if thisTrigger is "Application launched" then
set appName to |applicationName| of eventArgs
if appName is "Spotify" then
tell application appName to quit
end if
end if
end run
A free alternative is Hammerspoon, although one may find it is not as easy to implement and use as e.g. EventsScripts.
Here is an example of the code used to watch for the target application has launched and then close it using AppleScript code:
Example Lua code:
function applicationWatcher(appName, eventType)
if (eventType == hs.application.watcher.launched) then
if (appName == "Spotify") then
hs.applescript('tell application "Spotify" to quit')
end
end
end
appWatcher = hs.application.watcher.new(applicationWatcher)
appWatcher:start()
This would be placed in the ~/.hammerspoon/init.lua file and with Hammerspoon running in the background, when the target application is launched, it is told to quit via AppleScript.
Note: I am not affiliated with the developer of Hammerspoon, just a satisfied user of the product.
Hello I am using this Apple script in Automator to auto launch and play in full screens video using quick time.
tell application "QuickTime Player"
set theMovie to open file "Users:ronaldwise:Movies:Jarvis Startup.mp4"
tell theMovie
set the presenting to true
set the looping to false
play
end tell
end tell
The Script runs just fine when I press play in automator however, when I try and start the automation application outside of automator I receive this Message.
"The action "Run AppleScript" encountered an error "Not authorized to send Apple Events to QuickTime Player"
My Automation workflow looks like this
Workflow screenshot
I have allowed access to Security privacy > Accessability to the following apps: Terminal, Consul, AEServer, Automator, Consul, and Quicktime player.
I have allowed access to Security Privacy>Full Disk Access to the same above listed programs.
I have allowed access to Security Privacy > Automation to the following: Automator>QuickTime Player and Terminal>Finder
I am at a loss any help please.
The error has nothing to do with Accessibility and Full Disk Access
You have to add the key NSAppleEventsUsageDescription in Info.plist of the script application.
Open the application package in Finder with Right-click > Show Package Contents, then open the Info.plist file in Contents with a text editor and insert
<key>NSAppleEventsUsageDescription</key>
<string>Jarvis needs to control QuickTime Player</string>
The position of the key value pair is irrelevant but it must not follow directly a key line.
I'm attempting to script iTunes to play an arbitrary playlist or an arbitrary album from a shell script.
I've solved the playlist problem with the following:
osascript -e 'tell application "iTunes" to open location "'$url'?cmd=AddStation"'
Where url is an itmss:// type URL to a playlist. Without the "cmd=AddStation" parameter, it won't automatically play.
This doesn't work for an album URL, however. If I execute:
osascript -e 'tell application "iTunes" to open location "'$url'"'
where url is defined as an itmss:// album URL, then the album does come up on iTunes, but it won't start playing. If I tell iTunes to play via Applescript, it instead starts playing the first album in the entire iTunes library, not the album that is displayed.
There was a similar question about a year back here Applescript play music from iTunes URL ; however, the solution provided in that response requires you to know the title of the first track you want to play. Does anyone have an idea for a more generic solution that will bring an album from the command-line and then play the first track?
I am working on a project where I need to call methods on an existing application (my own) and use some of its functionality. For e.g. my application ThunderBolt runs on Mac OS X 10.10. It also provides a dictionary of events that can be called externally through Apple Script or some other way that I don't know yet.
My question is what are the different (and better) ways of interacting with an application programmatically on Mac OSX? If I use something like the following code in Apple Script Editor:
tell application "ThunderBolt"
set open_file to (choose file with prompt "Choose the file you wish to parse")
set theContents to read open_file as data
set retPict to (image convert theContents)
end tell
then it is going to launch ThunderBolt with a splash screen and then call "image convert". This can be done via NSAppleScript but still it would launch the application and call methods/events on it.
Is it possible to somehow create an instance of (or get a pointer to) one of the class inside the application and use that? Something similar to COM or automation on a Windows system?
If you're working on OS X 10.10, you might consider taking a look at JavaScript for Automation (JXA).
With it you can apparently build methods into your app that can be invoked from client scripts written in JS (although I'm not yet familiar with the particulars of how to handle implementation of such a thing on the app side). But many of the apps that ship as part of OS X Yosemite have such APIs built in (e.g. iTunes and Finder).
Here's a great tutorial on JXA written by Alex Guyot: http://www.macstories.net/tutorials/getting-started-with-javascript-for-automation-on-yosemite/
The JXA-Cookbook repo also appears to be a nice resource: https://github.com/dtinth/JXA-Cookbook/wiki
Here's a brief example - this script makes iTunes go back one track. Try it while iTunes is playing (by putting the text into Script Editor, with the language option set to JavaScript, and hitting the Run button):
iTunes = Application('iTunes')
state = iTunes.playerState()
// Console msgs show up in the Messages tab of the bottom view:
console.log("playerState: " + state)
iTunes.backTrack()
Alternatively, you can place the code into a .js file and run it on the command line:
$ osascript itunes-backTrack.js
playerState: playing
The way you specify the 'tell application' is the best way, in my opinion.
What do you do with your app that needs to be called? Maybe some of the functionalities can be done with Applescript? It would simplify things a lot.
I have iTunes on set up of my iMac to share an iTunes library between two different users. This means that if one person forgets to quit iTunes, the other user has to log in to the other account and quit itunes before they can use it on their own account.
So is there a way to use applescript to quit an application for all users? I know it's easy to tell it to quit an application for the current user, but haven't been able to figure out if it is possible to have it quit another user's instance of that application.
You can simply use an shell (terminal) command.
You can either enter killall iTunes in the terminal, or do shell command "killall iTunes" in Applescript.
It doesn't sound very healthy, but it's actually just a 'Forced Quit'.
I'm not on my Mac at the moment, so cannot look into this further.
But it may work better if you turn fast user switching off. Doing so will not stop two or more users logging in but will hide the GUI for it.
The create a Automator service or app or a Applecript/app or script. To run this AppleScript code.
tell application "iTunes" to quit
do shell script "'/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession' -suspend"
This code should quit iTunes and than show the login screen. Where the next user can login.
The other user will not be logged out.
Since I can't respond yet, I'll just do it this way:
Markhunte:
Make that
tell application "iTunes" to quit
do shell script "'/System/Library/CoreServices/Menu\\ Extras/User.menu/Contents/Resources/CGSession' -suspend"