From davidmailinglist at cloudgraphics.com Tue Oct 31 19:49:29 2006 From: davidmailinglist at cloudgraphics.com (David Heayn) Date: Tue, 31 Oct 2006 19:49:29 -0800 Subject: [LA.pm] app_running status to perl Message-ID: I'm currently trying to check if firefox is running before I edit pref files with perl (mac 10). #!/usr/bin/perl -w use strict; my $results; $results = system "osascript -e 'tell app \"System Events\" to count processes whose name is \"firefox-bin\"'>output"; print $results; Either way I run the above with firefox running or not running -though the terminal, my results are "0". I snarfed a small piece of code (for my project) from:: http://daringfireball.net/2006/10/how_to_tell_if_an_app_is_running The same page offers another way to figure out the status of a running app. Said author promotes detecting mac creator codes?!?! I would have sworn mac x killed off that metadata, and I couldn't find any online notes on how to figure firefox's creator code. I tried to check with "FileInfo"(shareware). Firefox apparently has ???? creator code. Either non-existant, or beyond display range? The last method on the web page is 10.4 specific, and I'm looking to build portable code (that won't break easily). David Heayn * http://www.cloudgraphics.com * (213)925.3283 From davidmailinglist at cloudgraphics.com Tue Oct 31 19:58:33 2006 From: davidmailinglist at cloudgraphics.com (David Heayn) Date: Tue, 31 Oct 2006 19:58:33 -0800 Subject: [LA.pm] app_running status... Message-ID: I meant to add this to the last email. If I call: system("osascript -e 'tell app \"System Events\" to count processes whose name is \"firefox-bin\"'") how do I return the shell results/truth back to a perl variable for a switch? David Heayn * http://www.cloudgraphics.com * (213)925.3283 From pete at peterbenjamin.com Tue Oct 31 22:05:08 2006 From: pete at peterbenjamin.com (Peter Benjamin) Date: Tue, 31 Oct 2006 22:05:08 -0800 Subject: [LA.pm] app_running status... In-Reply-To: References: Message-ID: <6.2.5.6.2.20061031215913.04d74578@peterbenjamin.com> At 07:58 PM 10/31/2006, you wrote: >I meant to add this to the last email. > >If I call: >system("osascript -e 'tell app \"System Events\" to count processes >whose name is \"firefox-bin\"'") > >how do I return the shell results/truth back to a perl variable for a switch? You could use back tics instead. $results = `osascript -e 'tell app \"System Events\" to count processes whose name is \"firefox-bin\"'` Otherwise, pipe it to a temp file. The exec instead of system should be looked to know all three ways of invoking commands outside of perl. I prefer backtics, and the return value can be an array of records. system("osascript -e 'tell app \"System Events\" to count processes whose name is \"firefox-bin\"' > /tmp/myscript_datetimestamphere" open (IN, "; close IN; Must do: Also, check $! to check that system returns no error. From pete at peterbenjamin.com Tue Oct 31 22:06:56 2006 From: pete at peterbenjamin.com (Peter Benjamin) Date: Tue, 31 Oct 2006 22:06:56 -0800 Subject: [LA.pm] app_running status to perl In-Reply-To: References: Message-ID: <6.2.5.6.2.20061031220527.04d74808@peterbenjamin.com> At 07:49 PM 10/31/2006, David Heayn wrote: >I'm currently trying to check if firefox is running before I edit >pref files with perl (mac 10). This should work, and be portable as well. my @so = `ps aux`; my @firefox = grep( //, @so );