Script to Swift - xcode

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.

Related

Custom Keyboard Shortcut Service Not Working 10.11 (el capitan)

I've seen a few questions dealing with this issue but nothing recently. I'm not sure if El Capitan (10.11) is breaking something, and I'm an AppleScript (and Automator) newbie.
I just want to have the basic functionality where a keyboard shortcut opens a new terminal window in the space I'm in. After doing the following things, absolutely nothing happens when I trigger the keyboard shortcut
1. Create an Automator Service
Open Automator and choose Service for my document type.
Set Service recieves selected to no input
Drag a Run AppleScriptaction into my workflow.
on run {input, parameters}
tell application "Terminal"
do script ""
activate
end tell
return input
end run
(At this point, running the workflow from automator by pressing Play opens a new terminal window correctly).
Save the service as Launch New Terminal Window
2. Assign a Keyboard Shortcut
Open System Preferences -> Keyboard -> Shortcuts -> Services
Assign Shift Command T to Launch New Terminal Window
When I try my new command, nothing happens.
Note, I tried to delete the service and retrace my steps. When I recreated a new service with the same name, the keyboard shortcut was remembered by the system. Does anyone know which .plist/where these keyboard shortcuts are saved?
If anyone can help me out, that would be great. A 30 second project has turned into 30 minutes of hair pulling.
I also encountered a similar problem. The issue is that, most probably some other application is using the key combination that you tried. You can check by using a bizarre key combination and check whether it works and then modify it. Try using something like Shift + alt + command + G. Or something like this ( use at least 4 keys ). It worked for me. Hope it helps you.
For future reference, since it seems a very common question, I think the only reason why a shortcut won't work is that it's being used by other application, as 2XSamurai said.
You can have quick feedback if the shortcut is going to work or not by navigating to Finder and then Services.
If your brand new shortcut is showing next to the service you created, that means is going to work, otherwise, it won't.
No need to perform other actions, you just need to pick a good shortcut. Somewhere on the web, you may also read that you must include the command key to make your shortcut work. That's also not necessary (see the screenshot with just ctrl + T combination working just fine).
PS I can't post pictures on answers yet so StackOverflow generated links to the images instead, but this caused the answer to broke (I was getting a message error stating there was code in my answer (??), so no screenshots, sorry, I hope the answer is clear enough even without them :)
I did exactly what you've described (Automator Service, no entry, only one Applescript Action, and assign the Automator Service to short cut key (in my case command shift Y).
All is working OK on my ElCapitain with bellow script in Automator action : (I mean the short cut opens a new Terminal window as expected)
tell application "Terminal" to activate
tell application "System Events"
tell process "Terminal"
keystroke "n" using {command down}
end tell
end tell
But I still ask myself the basic question : what do you really want to achieve ? usually the bash instruction could be done in do shell script command...no need for Terminal window... may be you have an other constraint.
I had the same problem before, solved it somehow, forgot about it and ran into it again when setting up a new MacBook today.
This solution works for me on several Macs:
Instead of using System Preferences -> Keyboard -> Shortcuts -> Services (screenshot 1 - for some reason I'm not allowed to insert pictures directly into posts) you can use
System Preferences -> Keyboard -> Shortcuts -> App Shortcuts (screenshot 2).
There you have to spell out the name of your service.
There are some issues with the App Shortcuts menu as well. For example a shortcut for the "Tags..." menu in Finder simply won't work but for services it works for me.

Create installer that runs application on login

I have spent more time on this task than I did actually creating the application.
I want to create an installer for my app that will:
Install the app into /Applications
Make the application launch on boot (it's just a menu bar status based app)
Number 1 is easy but I can get absolutely nowhere with getting #2 to work. I know I need to setup a postscript install somewhere I don't know how to make the script (I believe I need to put it in loginitems) and how to make it initialize as part of the package. My understandign from research is I need to look into making a postflight script but there is nothing at all in Package Manager for that.
Can someone please point me to something that works in 10.6+?
I've tried the script here in Add app to OSX "Login Items" during a Package Maker installer postflight script but it doesn't really explain where/how to actually add the script.
Launch at login can be a piece of cake or an absolute nightmare depending on wether or not your app is sandboxed. If it isn't sandboxed, then you can use LSSharedFileList to modify the login items preference pane: https://github.com/Mozketo/LaunchAtLoginController
If it is sandboxed then you're going to need to create a helper app: http://blog.timschroeder.net/2012/07/03/the-launch-at-login-sandbox-project/
The above tutorial didn't work for me on yosemite, I had to follow apple's sample code: https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLoginItems.html#//apple_ref/doc/uid/10000172i-SW5-SW1
As for the installer, check this answer here: https://stackoverflow.com/a/11487658/1320911

Applescript Error with Spotify play command

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.

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.

Do webdevelopers need "confim resend" protection?

I use firefox for my web development and I bet most of you guys too. I've been doing a lot of form development recently and this annoying message
"To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."
is just beginning to piss me off.. I mean, come on! I don't need protection on my localhost, thank you! So, my question is: are you aware of any config, hack, plugin to suppress it? If not, how do you live with it?
Apparently there is neither configuration option nor extension to turn off this annoying confirmation window.
However, the workaround I use is as follows.
Download and install application AutoHotkey from: http://www.autohotkey.com/
Create the following script:
^f5::
Send {f5}
sleep 100
Send {enter}
Save with .ahk extension.
Double click to run it (a new icon should show up in the system tray).
Now every time you press Ctrl+F5, the script presses F5 and then Enter. Voila, the confirmation window supressed.
Here's an equivalent of Patrick's answer for Linux users (Ubuntu in my case).
Install autokey (it's in the repos). Add this python script:
import time
keyboard.send_keys("<f5>")
time.sleep(0.5)
keyboard.send_keys("<enter>")
Hook this script to f5 and you will never see the confirm message again. Tested with latest firefox.

Resources