Applescript Error with Spotify play command - applescript

I've started experimenting with writing apple scripts, and would like to interface with spotify, however it hasn't been playing nice. When I send commands from terminal such as
osascript -e 'tell application "Spotify" to play'
It returns the error: 30:34: execution error: The variable play is not defined. (-2753).
It doesn't seem to be a problem with any other applications, so I was wondering what could be causing this/how do I fix it.
Any help would be greatly appreciated!
P.S. I'm basing most of this off of the shpotify script found here: https://github.com/hnarayanan/shpotify/blob/master/spotify
It doesn't run on my computer either, returning similar errors as above.

I had the same issue, and this is what fixed it:
Go to the finder and type command+shift+g, then enter this:
/Applications/Spotify.app/Contents/
Then, double click on "Info.plist", edit the "Scripting definition file name" field value (on the right) so that it reads "applescript/Spotify.sdef" instead of "Spotify.sdef"
Save it, restart Spotify and it should work now.

Related

Get Apple Events from AppleScript

I have a simple AppleScript which tells me url of active window in specific browser
tell application "Opera"
get URL of active tab of window 1
end tell
However I would like to see Apple Events needed to run that script, probable some of these: https://developer.apple.com/documentation/coreservices/apple_events?language=objc
My final goal is to code same script but using Apple Core Services.
I have checked Script Editor but I do not see any tab or menu where that information is displayed. Is there any way to translate that script?
Thanks in advance and regards
Yes, there are several such ways. My favorite is to use Script Debugger, which just translates the AppleScript into raw Apple events for you. Alternatively, you can run your AppleScript in an environment where export AEDebugSends=1; export AEDebugReceives=1 has been turned on.

Connecting firefox "open with" with Automator script

I managed to make Firefox to follow specific protocol links (oxygen:/...) and use an application to open them. As the Mac OS X oXygen XML Developer app doesn't accept arguments, I need to use a shell script that is shipped together with oXygen itself. Given Firefox doesn't like shell scripts, I needed to write an Automator application 'Run Shell Script'. As I was having trouble to get it to work, I decided to use a stub code, with osascript, just to debug variables.
My current script looks like:
osascript -e 'display alert "'"$1"'"'
and it is defined as a bash script, receiving data as arguments.
When I click the link the dialog of osscript appears, but with an empty message. So, I am not sure how the URL is being passed to the application itself. I tried, also, with receiving data as stdin, but with no lock. I got to the point of writing a script that dumped all the parameters and STDIN to a file, but it ends up always empty.
Thank you for any hint.

Script to Swift

I searched a lot but couldn't find any solution. I wrote a basic script on my mac that will open steam,write my password and keystroke return. It worked fine as a script then I import this code to xcode to make UI,added steam button and exported as "shortcuts.app" so when I press the steam button steam runs but but it doesn't enter my password neither keystroke return. I tried to upload the code to github. I believe there is a simple solution for this that I don't know.
https://gist.github.com/abigado/25a429efd98d439dc78d
By the way I get this when I build the app in xcode but app runs. Don't know if this is the problem.
2015-06-27 20:07:37.404 Shortcuts[877:18363] Failed to connect (theWindow) outlet from (NSApplication) to (NSApplication): missing setter or instance variable
Remove the second script AppDelegate– and probably corresponding end– line.

Apple Script application control

Thanks for reading my question. I have an issue I was hoping you could help me with. the following apple script will run but ends up timing out because the application is not selected; the icon just bounces on the mac server dock (OSX 10.85). What am I doing wrong?
tell application "(Application Name)"
activate
getURL "(Server URL)"
delay 30
tell database "(database name)"
do script "(Script Name)"
delay 60
close
end tell
end tell
do shell script "(Shell script path)"
Also, I'd like to tell the application to quit prior to running the shell script.
Any and all advice would be appreciated.
THANK YOU!
To quit an app, all you do is put a “quit” command inside its tell block, typically as the last command in the tell block:
tell application "Safari"
quit
end tell
Verify that “getURL” is the right command for the app you are targeting. The modern version is “open location.”
When you run your script from AppleScript Editor, you can tap on “Event Log” at the bottom of the window and see a log of events that occurred during your script’s execution. You can often see what went wrong there.
If your AppleScript is what is timing out, you can use with timeout:
with timeout of 3600 seconds
-- do something within an hour
end timeout
As jweaks said, you need to provide more information to get real help. Every application extends AppleScript in its own way. Your script may be perfect or it may not. There is no way for someone to know without knowing what application your script runs on. It’s like asking for help with Photoshop work but not telling anyone it is Photoshop you are working in.

Error code -10810 when calling "open" from applescript

I'm trying to use AppleScript to modify some app settings. The code looks like this:
#!/bin/sh
echo '
tell application "Finder"
tell disk "'$1'"
open
set current view of container window to icon view
...
close
end tell
end tell
' | osascript
However, I keep on getting a -10810 error code when applescript hits "open" ("64:68: execution error: An error of type -10810 has occurred. (-10810)"). I've done some googling and all I got was "reboot and wait, it sometimes magically starts working" (it didn't).
The machine is running Mac OS Server 10.6. I though it perhaps might be some permissions issue, but running the command as root returns the same error.
Update: Solved (well, more or less :-) ). The thing is that "open" needs a UI. And the problem was that I was using ssh to run the script (which I didn't mention here, because I didn't think it was relevant). So there was no UI. It works when I log in using VNC first.
Solved (well, more or less :-) ).
The thing is that "open" needs a UI. And the problem was that I was using ssh to run the script (which I didn't mention here, because I didn't think it was relevant). So there was no UI. It works when I log in using VNC first.

Resources