Xcode 4.1 behaviours - automate closing a tab? - xcode

I have my behaviours set up so that on successfully running a build, Xcode will open a custom debug window. I would like to then close this window when the run completes, however I cannot see an option for this. The best I can manage is returning focus to my main window without closing the debug window.
I have a two monitor setup and most the time use the second monitor for the Xcode organiser. Obviously the debug window is of more use to me when running the application, however I would like to have my organiser back on top afterwards.
Is there any 'Close Tab' behaviour or similar in Xcode 4.1?
Thanks
Update:
Just to say that I've filed a feature request with Apple. Since most of the other behaviours have options (a pop-down menu) to show/hide, it seems only natural that this should be an option for tabs/windows also.

I developed an Xcode plugin (Code on Github) that closes the debug window automatically after the debug session has ended. The plugin was developed and tested with Xcode 4.2.1 but should work with 4.1.
Usage
Download "Xcode Auto Close Debug"
Unzip it.
Move XcodeAutoCloseDebug.xcplugin to ~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/
Restart Xcode
Open menu "Xcode" -> "Preferences" -> "Behaviors" -> "Run Starts".
Activate "Show tab" and set the tab name "XcodeAutoCloseDebug" (this exact name is important!)
Run the executable and detach the debugger window (drag the tab out of Xcode to create an own window).
Stop the executable and the window should close automatically.
... let me know if you experience any problems.

You can run a shell script when run completes (don't forget to make it executable) :
#!/bin/sh
osascript ~/Documents/close-xcode-tab.scpt &
And the I use the AppleScript Editor to create the scpt file :
tell application "System Events"
tell application "Xcode" to activate
tell process "Xcode"
tell menu bar 0
click menu item "Close Tab" of menu "File"
end tell
end tell
#keystroke "w" using {command down}
end tell
It will take 1-2 seconds to close the tab (but if you edit the script to only send the keystroke, it'll close quickly).
The limits are that we can't be sure to close the "good" tab as xcode4 don't let retrieve tab name (it's possible with safari).

Related

AppleScript, why does first "display alert" work but then cause AppleScript icon to bounce, waiting for me to click it until I get another dialog?

NOTE: I do not have Admin privileges, and cannot use things that require assistance or accessibility or whatever it is!
I'm basically trying to write an execution of a script that sets up my macOS Desktop by opening apps, positioning them etc
Part of that is allowing me to click continue on a dialogue after doing certain things I have to do manually as a result of the limitation (positioning a few apps for example).
I can successfully have the first alert pop up, and when I press OK, it executes the task, but then the 2nd alert is hidden behind AppleScript and will not pop up until I click AppleScript. Anyone know why?
Heres what I have, and please keep in mind I do not have Admin privileges, which means I can't use System Events:
tell application "Script Editor"
set miniaturized of window 1 to true
end tell
display alert "App is opening. Make sure you log-out of Apple Connect!"
delay 3
tell application "Safari"
activate
make new document
set the bounds of the front window to {1077, 23, 1581, 464}
tell window 1
set URL of tab 1 to "http://appwebsite.com"
end tell
end tell
display alert "Set up App, sign into Apple then click OK to open all other Safari windows"
delay 1
tell application "Test Task App" to activate
Place an activate command before the display alert command so Script Editor has focus and the display alert command will not be hidden.
Example:
activate
display alert "Set up App, sign into Apple then click OK to open all other Safari windows"
You do not need it before the first one as Script Editor has focus with it runs the first display alert command, but once you activate Safari, the display alert command is behind Safari. So if you use an activate command before the display alert command, it brings it forward in front of, in this case, Safari.

Perform actions on a certain window of the application with AppleScript

I'm building a macOS app for managing locations sent to an iOS device via GPX file in Debug mode, so I need to have to Xcode windows opened for each project. I got an AppleScript which presses Debug -> Simulate Location -> "my gpx file name" for continuous location updates. However, it works only if the window with an iOS project (through which I simulate the location) is frontmost.
I want the script to be able to perform said actions just on a window with a certain name (or rather whose name contains ...), no matter of the hierarchy. I don't want it to be brought to the front or activated, as I might be coding something in a second one while the script runs.
I tried many ways, but with my limited understanding of AppleScript I either get an error (like "Can't locate menu item 1 in bla-bla-bla of the process Xcode) or the window activates and doesn't work in the "background".
repeat while true
tell application "System Events" to tell process "Xcode"
click menu item "MyLocation" of menu 1 of menu item "Simulate Location" of menu 1 of menu bar item "Debug" of menu bar 1
end tell
delay 0.2
end repeat
Is it even possible to perform any action on inactive window? I thought it is since the system lets you scroll without focusing the window.

Accessing an Applescript from 2 different menus produces different results. Why?

I've got an application that has an embedded Script menu for running Applescripts. However, if you try to run scripts with certain functions (mostly UI related) they won't work unless you run them from the System script menu (in menu bar).
For example, if in theApplication you say :
tell application "System Events" to tell application process "theApp" to get all windows
it will return an empty list if run from the program's script menu, but 2 if run from the system script menu. I've also tried:
tell application "System Events"
tell application process "theApp"
set allElements to UI elements
display dialog (count of allElements)
end tell
end tell
-- returns 2 when run from System script menu but 0 when run from within theApp.
Also if you run from the Script Editor it will work fine. GUI scripting is enabled for the application in System Preferences, so I'm curious as to why this is happening, and any workarounds for it (other than run the script from the System Script menu)? The Dictionary shows Standard Suite so it should have access to windows...
Any ideas?
I believe you haven't provisioned the app in question to use assistive devices.
You should really open System Preferences, then click the button for "Security", then unlock, and click the button for Assitive Devices, (the blue icon with a white man), then drag your app onto it (reveal your app from its Dock menu), and permit it to control your machine, remember to lock the pane afterwards.
I can not guaranttee this to work, but it is certainly worth a try.

Can I assign the "New Window" hotkey in Mac OSX to a particular theme?

In the Mac OSX Terminal app, I want to press command-N and get a new window with the Homebrew theme. I have edited my preferences so that on startup of the Terminal app I get a Hombrew-themed window, but I'd like to be able to create new windows (and tabs if that's not too much to ask for) with that same theme.
I've tried assigning a new hotkey in System Preferences -> Keyboard -> Keyboard Shortcuts -> Application Shortcuts. I created a new hotkey for Terminal, and specified "Homebrew" as the command. This did not work. have I specified the name of the menu command incorrectly, or am I just going about this wrong?
I also dug around a bit in the Terminal.app folder (using the shell), looking for a config file where I could set this, but no luck.
Any ideas?
Thanks!
James
You can change the default profile by clicking the default button under the list of profiles in the second tab.
If others were looking how to create a window with a specific profile, you can change the current settings property or use UI scripting:
tell application "Terminal"
do script ""
set current settings of window 1 to settings set "Homebrew"
end tell
tell application "System Events" to tell process "Terminal"
click menu item "Homebrew" of menu 1 of menu item "New Window" of menu "Shell" of menu bar item 3 of menu bar 1
end tell

AppleScript code that clicks a button in NSAlert

I have an mac application that once opened (in awakeFromNib) shows the user an NSAlert with two buttons, one with "Option1", the other with "Option2". I would like to automate the following flow:
Open the application from the Applications folder.
Choose "Option2" by clicking the button in the NSAlert
So far I've managed to do only the first part:
tell application "Finder"
activate
make new Finder window to startup disk
open application file "My Application.app" of folder "Applications" of startup disk
close Finder window 1
end tell
Can anybody help me with the code? I understand that I can use the System Events commands to catch this click event, but can't manage to find any help online for clicking a button in an NSAlert, and not in a regular Window.
You might try this...
tell application "My Application" to activate
delay 5
tell application "System Events"
tell process "My Application"
click button "option 2" of window 1
end
end
How many windows do you have open? It's probably getting confused.
If you need to the program UI Browser can generally find the proper terms for GUI Scripting. I'm not sure it's worth buying just for this but you can run the program in demo mode for a month and use it to find the proper terms.
http://pfiddlesoft.com/uibrowser/

Resources