Is there a script option to actualy go through all XCode opened projects (application windows) and execute menu action Product->Stop or executing shortcut "CMD + ."?
To run Apple Script in Xcode at the beginning of each run You can create shell script like so:
#!/bin/bash
osascript -e 'tell application "Xcode"
activate
set activeWindow to window 1
set windowName to name of activeWindow
repeat with aWindow in windows
tell application "System Events" to keystroke "`" using command down
if name of aWindow is not equal to windowName then
if name of aWindow is not equal to "" then
tell application "System Events" to keystroke "." using command down
end if
end if
end repeat
end tell'
Then in Xcode go to Preferences->Behaviours->Starts->Run and choose Your script.
Related
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.
What I would like to do is have an automator script open a file in emacs when I drag a file onto it, and bring terminal to the front.
Right now, when I try to do this with input set to ~/Desktop/test.txt, it either opens up the main page, or it ends up with ~/Desktop/testtxt. Am I doing this wrong? Is there a better way to do this?
This is what I have right now:
set thePath to POSIX path of input
tell application "Terminal" to do script "emacs"
tell application "System Events"
tell process "Terminal"
activate
delay 2
keystroke "x" using control down
delay 1
keystroke "f" using control down
delay 1
keystroke thePath
delay 1
keystroke return
delay 1
end tell
end tell
return input
end run
Use the file path as an argument to emacs
on run {input}
tell application "Terminal"
repeat with i in input
do script "emacs " & quoted form of POSIX path of i
end repeat
activate
end tell
return input
end run
I´m trying to create a keyshortcut to open terminal in current folder. Looking around, I found this code to create a service (the part of adding the shortcut to this service is solved), only added things are the "; clear" and some of the "activate" so it shows
on run {input, parameters}
tell application "Finder"
activate
set myWin to window 1
set theWin to (quoted form of POSIX path of (target of myWin as alias))
tell application "Terminal"
activate
tell window 1
activate
do script "cd " & theWin & ";clear"
end tell
end tell
end tell
return input
end run
It is not working as i would like.
troubles:
it opens two windows in terminal, have no idea why. It has nothing to
do with the added "activate"… it has always donde that
if I select an item on finder ( a folder ) it opens its parent directory and i would
like it to open the selected folder
this is my very first try with Applescript so if the error is obvious i just can't see it
Thanks in advance
The do script command already opens a window in Terminal. Try it this way:
tell application "Finder" to set theSel to selection
tell application "Terminal"
set theFol to POSIX path of ((item 1 of theSel) as text)
if (count of windows) is not 0 then
do script "cd " & quoted form of theFol & ";clear" in window 1
else
do script "cd " & quoted form of theFol & ";clear"
end if
activate
end tell
I like the reopen approach better...
tell application "Finder" to set currentFolder to target of front Finder window as text
set theWin to currentFolder's POSIX path
tell application "Terminal"
if not (exists window 1) then reopen
activate
do script "cd " & quoted form of theWin & ";clear" in window 1
end tell
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}
I Want to make a new Folder command in apple script
Why dosent this script work?
tell application "Finder"
activate
end tell
tell application "System Events"
tell process "Finder"
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item "New folder"
end tell
end tell
end tell
end tell
end tell
You can do it more directly with AppleScript:
tell application "Finder"
set p to path to desktop -- Or whatever path you want
make new folder at p with properties {name:"New Folder"}
end tell
I don't know if running bash commands within AppleScript is cheating, but you can also do:
do shell script "mkdir ~'/Desktop/New Folder'"
Which is useful when you need to create sub folders on-the-fly when they don't exist yet:
do shell script "mkdir -p ~'/Desktop/New Folder/Bleep/Bloop'"
tell application "Finder"
activate
end tell
tell application "System Events"
tell process "Finder"
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item "new folder"
end tell
end tell
end tell
end tell
end tell
--you capitalize the N in new folder the new folder button is not capped.
NOTE: This can fail for two reasons;
(1) '~' trapped in singlequote won't parse.
(2) space in '/New Folder/' will break the path.
do shell script "mkdir -p '~/Desktop/New Folder/Bleep/Bloop'"
SOLVED:
do shell script "mkdir -p ~/Desktop/" & quoted form of "New Folder/Bleep/Bloop"
You can directly with an applescript script by simulating keystroke on ("N" and command and shift) this will create a new folder on the desktop or in the open Finder window.
Below the script, you can test it in the script editor
tell application "System Events" to tell process "Finder"
set frontmost to true
keystroke "N" using {command down, shift down}
end tell
Your script works if you add under "tell process" Finder "
"set frontmost to true"
Which give
tell application "System Events"
tell process "Finder"
set frontmost to true
tell menu bar 1
tell menu bar item "File"
tell menu "File"
click menu item "New folder"
end tell
end tell
end tell
end tell
end tell
tell application "Finder"
set thepath to alias "Macintosh HD:Users:JasonMagnuson:Documents:" as text
make new folder at thepath with properties {name:"nov_archive"}
end tell