I'm trying to do a script to quit Xcode with currently building application. My current script only cover to quit Xcode but I'm unable to handle the confirmation dialog box that pop-ups on the Xcode. On the confirmation box, there are two button options: Cancel or Stop Tasks. I wanted to click on Stop Tasks button. Please help.
Here's my current AppleScript so far:
set apps to {"Simulator","Xcode"}
repeat with thisApp in apps
tell application thisApp to quit
end repeat
tell application "System Events"
tell process "Xcode"
click button "Stop Tasks" of sheet 1 of window 1
end tell
end tell
This is my current applescript that didn't work.
I'm able to fix my issue regarding terminating Xcode with confirmation dialog box prompt. Here's my the applescript I've come up:
try
with timeout of 10 seconds
quit application "Simulator"
quit application "Xcode"
end timeout
on error number e
if e is -1712 then
activate application "Xcode"
tell application "System Events"
tell application process "Xcode"
keystroke return
end tell
end tell
end if
end try
Related
How to close the "Your computer was restarted because of a problem" popup in AppleScript?
We use a VM to execute e2e tests and they often fail because of this popup. I would like to programmatically close it.
I tried listing the windows based on https://stackoverflow.com/a/26196136, but the popup is not included in the list
tell application "System Events"
tell application process "Diagnostics Reporter"
if (exists window 1) then click button "Ignore" of window 1
end tell
end tell
I want Applescript that trigger as soon as Mail app opens and if mail app opens then it should wait for 10 seconds and after that it should activate the previous app (like what cmd + tab does).
I have used the following code but in order to achieve that, it should run in the background all the time. I have no clue how to achieve this.
tell application "System Events"
set frontmostApplicationName to name of 1st process whose frontmost is true
end tell
tell application "Mail"
activate
end tell
tell application frontmostApplicationName
activate
end tell
One of my application processes occasionally creates a floating window that I'd like to programmatically auto-close.
I have no problem checking for the existence of this window through its name, but then I am unable to close it with neither close window "windowname" nor tell window "windowname" to close.
E.g.:
tell application "System Events" to tell process "processname"
if exists window "windowname" then
close window "windowname"
end if
end tell
This result in:
error "System Events got an error: window "windowname" of process "processname" doesn’t understand the “close” message."
How can I close this window, then?
I can close a Finder window like this. Maybe you can do the same.
tell application "System Events"
tell process "Finder"
click button 1 of window 1
end tell
end tell
If "Command-W" closes the floating window, which it usually does, this will work:
tell application "System Events"
if exists window "<window name>" of process "<application name>" then
keystroke "w" using command down
end if
end tell
You can also use Automator instead of AppleScript proper to do this. Record yourself clicking the close button.
When I do this, Automator records the action as, I kid you not, Click the "<fill in title>" button.
Basically my goal is to code a key command (option-s) to activate Stickies and create a new note. Right now I have an Alfred 2 generated Automation which links the hot key to the following script:
on alfred_script(q)
tell application "Stickies" to activate
delay .2
tell application "Stickies" to activate
delay .01
tell application "System Events"
keystroke "n" using command down
end tell
end alfred_script
The two activate commands are my attempt to deal with a bug where it opens the application, but doesn't bring it to front. It works seamlessly when the application is open in the background, but it's slow and creates a screen flash when the application isn't already running. The delay is not coming from the application itself because I can open the application and hit command-n as fast as possible, and it always works.
(By the way if you have an idea for how I could hide all other notes and just show the new one, that would be awesome!)
Try this:
launch application "Stickies"
tell application "System Events" to tell process "Stickies"
click menu item "New Note" of menu "File" of menu bar 1
set frontmost to true
end tell
If you run the script by pressing option-s, there might not be enough time to release option before keystroke "n" using command down.
Or this doesn't raise the windows for other notes:
launch application "Stickies"
tell application "System Events" to tell process "Stickies"
click menu item "New Note" of menu "File" of menu bar 1
end tell
do shell script "open -a Stickies"
activate app "Appname" and set frontmost of "Appname" to true raise all windows, but do shell script "open -a Appname" raises only one window.
Hotkeys also have a short delay by default in Alfred, but you can reduce it by changing the trigger behavior:
You could try this alternate way, might have a different effect.
tell application "System Events"
tell process "Stickies"
set frontmost to true
keystroke "n" using command down
keystroke "Hello World" & linefeed & "I'm a new note!"
end tell
end tell
Hiding all other notes, i'd say start a new question for that.
Haven't ever scripted with apple script before was wondering if it was possible to create an applescript that could toggle the settings for messages in the notification that displays the message preview. I was then gonna use quicksilver to call that script, is this possible with applescript and would quicksilver be able to make the appropriate calls to initiate the script? I'm running mavericks OS.
This toggles the "Show message preview" checkbox:
tell application "System Preferences"
reveal pane id "com.apple.preference.notifications"
end tell
tell application "System Events" to tell window 1 of process "System Preferences"
repeat with r in rows of table 1 of scroll area 1
if name of UI element 1 of r is "Messages" then
set selected of r to true
exit repeat
end if
end repeat
click checkbox "Show message preview" of group 1
end tell