XCode 5 behavior script generating permission error - xcode

This morning I thought I'd spend a few minutes to write an XCode 5 script for Prefereces->behaviors to hide panels to better focus on Code and storyboard. A few command keys: how long can that take.....
I used AppleScript, and it runs fine from the applescript editor. I then exported it as a script bundle and hooked it to a behavior within XCode. When I hit the key command, I get the permissions error:
Failed to launch script /Users/sss/Documents/pers/XCode Scripts/XCodeCodeFocus.scptd: The operation couldn’t be completed. Permission denied
The AppleScript is very basic: I've tried:
activate application "Xcode"
tell application "System Events" to keystroke "Y" using command down
tell application "System Events" to keystroke "0" using {command down, option down}
tell application "System Events" to keystroke "1" using command down
and (without the activate command in case that's causing havoc)
tell application "System Events" to keystroke "Y" using command down
tell application "System Events" to keystroke "0" using {command down, option down}
tell application "System Events" to keystroke "1" using command down
File permissions on the file are:
drwxr-xr-x# 3 sss staff 102 Oct 4 06:31 XCode Code Focus copy.scptd
The file is in my code directory, but I can't see why that would affect things.
Is this broken in XCode 5, or am I missing something....
many thanks!

Related

In MacOSX, can't get applescript+automator service working to send text from any application to "Sublime Text 3"

Want to send text from any application to "Sublime Text 3" and this is how I am thinking of doing it
Create an "automator" service
Set a shortcut for it
Call shortcut from app
I am able to create the "automator" service and it works fine when tested from within "automator" (by means of the "Get Text" action)
But, when I trigger shortcut from application, "Sublime Text" does not open new tab with the selected text (and does nothing)
This is how I am setting up the "automator" service
Service receives selected text in any application
Copy to Clipboard
Run this applescript
on run {input, parameters}
tell application "System Events"
set frontmost of process "Sublime Text" to true
tell application "System Events" to keystroke "n" using command down
tell application "System Events" to keystroke "v" using command down
end tell
end run
Appreciate the help, thanks
The following example AppleScript code works for me:
on run {input, parameters}
tell application "Sublime Text" to activate
delay 1
tell application "System Events"
keystroke "n" using command down
delay 0.5
keystroke "v" using command down
end tell
end run
Note that the value of the delay commands may or may not need to be adjusted for timing on your system.

Applescript Keystroke "⌘+" gives an error

My applescript isn't working. I want a keystroke that does ⌘+ on my mac.
Here is my current code.
set abc to "+"
tell application "System Events"
keystroke command & abc
keystroke a
end tell
When I click play, I get the error
"System Events got an error: Can’t make {command, \"n\"} into type text." number -1700 from {command, "n"} to text.
Anyone know how to fix this?
The syntax to press modifier keys is
set abc to "+"
tell application "System Events"
keystroke abc using command down
end tell

How to send dot in AppleScript

I want to upload a file using AppleScript in Chrome. The file path contain a dot (.), but this script is not able to send the dot to 'Go to the folder:'.
on run argv
tell application "System Events"
tell application "Google Chrome" to activate
delay 2
log argv
keystroke "g" using {command down, shift down}
delay 1
keystroke item 1 of argv
end tell
end run
I am running the script with this command:
nsadmins-Mac:util nsadmin$ osascript macUploadChrome.scpt "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py"
This text appears in the "Go to the folder" field after running this script:
/System/Library/Frameworks/Pythonframework/Versions//lib/python/socketpy
That's weird, but what if you try using copy/paste instead:
set the clipboard to (item 1 of argv as string)
keystroke "g" using {command down, shift down}
delay 1
keystroke "v" using {command down}
Why Chrome? Honestly curious, I never have any problems with Safari. Anyways,
--set filepath to POSIX path of theimage
--^^set filepath to the desired file path^^
delay 2
tell application "System Events"
activate application "Safari"
delay 0.5
keystroke "g" using {shift down, command down} --open goto
set the clipboard to filepath
keystroke "v" using {command down}
delay 0.7
keystroke return -- enter goto text
delay 0.4
keystroke return --press enter on file
end tell
Maybe that filepath is just too long. I doubt it though. Try using this, if it doesn't work with Chrome try it with Safari just to see if that's the problem. This is meant to be run when the "file choosing window" is already open, but the full script that I wrote is a bit more extensive, let me know if you want to see it.

Run a command in a new tab in terminal

I'm trying to write a script that could run several commands in several tabs in the terminal.
I found a lot of informations about it, but it doesn't work as I want it to. So I probably need AppleScript.
• This code run a command in a new window:
tell app "Terminal"
do script "echo hello"
end tell
• And this one open a new tab
tell application "Terminal"
activate
tell application "System Events"
keystroke "t" using {command down}
end tell
end tell
But I didn't figured out how to "mix" them. Any idea ?
tell application "Terminal"
activate
tell application "System Events"
keystroke "t" using {command down}
end tell
do script "echo hello" in selected tab of the front window
end tell

Applescript to Expose all Finder Windows?

I'm trying to figure out how to write an Applescript that will Exposé all Finder Windows.
Application Logic
I think the script needs to have this application logic:
Check a residual setting and get the name of the last "Frontmost
Application" (perhaps use a text file ~/last-application.txt to store this?)
Grab the name of the current Frontmost Application
If the name of the current of the Frontmost Application is Expose, then activate the previous frontmost application
Else, activate finder, and then activate expose for just finder windows
Desired Behavior
When the script is activated all the finder windows (and only the finder windows) will be shown in Exposé
If the script is then run again (and no finder window was selected) the script will just switch back to the last frontmost application
I'm not sure how to get this working though. If there is another utility that does this automatically that'd be great, too.
set f to "/s/x/finderexpose"
set prev to do shell script "touch " & f & "; cat " & f
if prev is not "" then
delay 0.5 -- time to release modifier keys used in a shortcut
tell application "System Events" to key code 53 -- esc, if Exposé is open
delay 0.3 -- for the Exposé animation?
activate application prev
do shell script "echo '' > " & f
else
do shell script "echo " & quoted form of (path to frontmost application as text) & " > " & f
activate application "Finder"
delay 0.05
tell application "System Events" to key code 125 using {control down} -- ⌃↓
end if
It'd be less ugly if the part for switching to the previous application was left out:
activate application "Finder"
delay 0.05
tell application "System Events" to key code 125 using {control down}

Resources