• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: User Scripts
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: User Scripts


  • Subject: Re: User Scripts
  • From: Andreas Grosam <email@hidden>
  • Date: Fri, 16 Jan 2009 21:13:26 +0100


On 16.01.2009, at 19:59, Craig Williams wrote:


On Jan 16, 2009, at 10:17 AM, Craig Williams wrote:

On 16.01.2009, at 02:43, Philip Aker wrote:
On 2009-01-15, at 11:00:32, Andreas Grosam wrote:
how can I ensure that an application launched from a user script will be put to the foreground and becomes the active application, which possibly opens a modal dialog when it starts up?
I call this simple script:
#!/bin/sh
$HOME/Applications/DiffMerge.app/Contents/MacOS/DiffMerge - nosplash "%%%{PBXFilePath}%%%"
The app not always launches in the foreground or is behind a Xcode editor window, and it also does not always become the active application. That is, Xcode still might be the active application, but the launched tool may be in the foreground.
When started, the app opens a modal dialog - which might be the culprit. Without causing the app to open a modal dialog at its start up, all seems working well: it is put to the foreground and it also becomes the active application.
I would like to use the command open instead, however, with open it seems it is not possible to pass program arguments.
How can I accomplish this in an easy way?
Try this:
#!/bin/sh
$HOME/Applications/DiffMerge.app/Contents/MacOS/DiffMerge - nosplash "%%%{PBXFilePath}%%%"
/usr/bin/osascript -e 'tell application "DiffMerge" to activate'

Thanks for the tip using AppleScript. Unfortunately, it won't work (yet). The problem now is, that two instances of DiffMerge will be launched. I guess, the problem is that the AppleScript runtime performs the "activate" command before the former process is actually established. So, a hack would be to insert a sleep() before the osascript command.

But this would also not solve my needs completely: there might be cases where one or more instances of DiffMerge are already running. The user script should ensure that exactly that DiffMerge instance will be put to the foreground which has been launched in this script.

I would prefere a pure Apple Script solution. However, the app DiffMerge is not scriptable - that is only the basic commands and built-in osascript commands will work. For instance this apple script snippet
‘launch application "DiffMerge"‘ works perfectly. If I were able to pass program arguments, and also get a PID (in order to refere to this app later) -- that would be great.



Andreas

Another way to get the last process is with: $!

To activate the application using it's PID try this.

set appID to 37146
tell application "System Events" to set frontmost of (every process whose unix id is appID) to true

Yes! This might do the trick. :)

I already knew the $! variable but I didn't know how to tell AppleScript to put a process with a certain PID to front.

So, the complete script looks like this:

#!/bin/sh
LEFT_FILE="%%%{PBXFilePath}%%%"
$HOME/Applications/DiffMerge.app/Contents/MacOS/DiffMerge -nosplash "% %%{PBXFilePath}%%%"&> /dev/null &
pid=$!
statement="tell application \"System Events\" to set frontmost of (every process whose unix id is $pid) to true"
/usr/bin/osascript -e "$statement"



It works like a charm! :)

Thank you Craig for the last peace to get it to work.


Andreas _______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Re: User Scripts (From: Craig Williams <email@hidden>)
 >Re: User Scripts (From: Craig Williams <email@hidden>)

  • Prev by Date: Re: Odd Top Level Objects Issue
  • Next by Date: Re: Odd Top Level Objects Issue
  • Previous by thread: Re: User Scripts
  • Next by thread: Refactoring halted due to supposed missing file
  • Index(es):
    • Date
    • Thread