↑back..

some words to not

nature is a fashion victim

since february 2004

"indecision may or may not be my problem."
jimmy buffett

08.02.05

 

tips-n-tricks

blocking mac launchers

mac os x has a unix base, and there's quite a lot of back-and-forth integration between the graphical o.s and the command-line one.

for example, you can type 'open -a <application> <file>' in the command line to launch any file into any application, or 'open -e <file>' to open something in the text editor, which is pretty convenient. 'opendiff <file1> <file2>' compares two text files in a gui and allows you to do merges using the FileMerge application.

one thing i couldn't find was a way to run these things in blocking mode. by default these launching programs return after having run the gui app in the background, but sometimes unix scripts want to know when a process ends, and you don't want the launcher to end before the gui program quits.

so i didn't find a general way to do it, but here's a script i endearingly call 'blocken-e' which can be used like 'open -e', but it's blocking, by waiting for TextEdit to finish:

#!/bin/sh
open -e $*
pid=`ps -ax | grep TextEdit | awk '{print $1}' | head -1`
nps=1
while [ $nps -ne 0 ]
do
nps=`ps ax | grep $pid | grep -v "grep" | wc -l`
done

with 'opendiff' its even easier. apparently if you backquote the launcher command it will block until FileMerge is quit, so you do this:

`opendiff file_a file_b -merge outputfile`

in some shells, the non-redirected output will cause trouble, so you can always do this instead:

echo `opendiff file_a file_b -merge outputfile` > /dev/null

if there's a more general way to do this, please let me know...

2 comments hide comments

Sat, 12 Feb 2005 18:06

Refer your quastion to this guy, Mitz Petel here:
307.forums.ort.org.il@mitzpettel.com

- Oren

Sat, 12 Feb 2005 18:18

who is that and why would he know?

- guy

use filters on the right to see additional content by month or category

content here by guy hoffman .. as seen times since march 2004

first letter of my first name, then my last name, at gmail-,-com

a picture of me
why this blog?
blog code (raw)
xml
searches

filter:

show recent
show all

months

0707
0807
0407
0307
0207
0107
1206
1106
1006
0906
0806
0706
0606
0506
0406
0306
0206
0106
1205
1105
1005
0905
0705
0605
0505
0405
0305
0205
0105
1204
1104
1004
0904
0804
0704
0604
0504
0404
0304
0204

categories

admin
america
animation
arts-n-crafts
books
boston
captain
cite
comments-on
design
film
flesh
future
israel
journalism
mit
motd
music
nostalgia
politics
radio
religion
robots
science
sports
tips-n-tricks
travel
useless

keep
procrastinating

ceerock
rude pundit

Eliminate DRM!
Protect your freedom!

you are sociable and entertaining