Hi, I have a command (html output) that will be run frequently to give a status update. Based on it's output, the user will make a change to their code and run it again. But it gets tedious having to click back onto the window every time they run the command.
Is there a way to have my command automatically switch back to the window they've been writing their text in, after displaying the output, so that the output updates, but user focus appears to remain in the editor window?
I hunted through some Applescript for the last hour, but haven't seen anything I could figure out how to use.
I tried recording the command with automator, it gave me
-- Press ⌘` delay 0.232022 set timeoutSeconds to 2.000000 set uiScript to "keystroke "`" using command down" my doWithTimeout( uiScript, timeoutSeconds )
on doWithTimeout(uiScript, timeoutSeconds) set endDate to (current date) + timeoutSeconds repeat try run script "tell application "System Events" " & uiScript & " end tell" exit repeat on error errorMessage if ((current date) > endDate) then error "Can not " & uiScript end if end try end repeat end doWithTimeout
Then I tried placing that in a system call to osascript at the end of my command, but it didn't seem to do anything.
On 29 April 2010 14:44, Josh Cheek josh.cheek@gmail.com wrote:
Hi, I have a command (html output) that will be run frequently to give a status update. Based on it's output, the user will make a change to their code and run it again. But it gets tedious having to click back onto the window every time they run the command.
Is there a way to have my command automatically switch back to the window they've been writing their text in, after displaying the output, so that the output updates, but user focus appears to remain in the editor window?
This of course depends on the kind of output your command is generating, but maybe you can set the output to "Show as Tool Tip"?
If anyone googles how to do this, here is the solution we found, it works with unsaved windows (hence the "untitled", you would have to change that depending on your use)
----------
In the command, execute the system comand (ours is Ruby, so backticks) `osascript switch_windows.applescript`
----------
Then in your Support directory, the file: switch_windows.applescript
tell application "TextMate" activate end tell tell application "System Events" set found_window to false set all_windows to every window of process "TextMate" repeat with w in all_windows if name of w contains "untitled" then set editor_window to name of w set found_window to true end if end repeat
if found_window then
tell process "TextMate" tell menu bar 1 tell menu bar item "Window" tell menu "Window" click menu item editor_window end tell end tell end tell end tell end if end tell