![]() |
Thank a lot
Your recommendations are very useful. Well, finding out existence of this script is a workaround to find out if app runs.
Firstly, I wrote a shell script where called osascript $COMMAND (where $COMMAND is apple script command). But this shell script is running from some app and performed under root (I can't change this). And on Leopard (and maybe on Tiger) osascript is not performed under root. So I tried to call from shell script "osasscript myscript.scpt". Seems that in this case myscript.scpt is not performed under root. But I need to know if app (for example "Address Book" is not running). For some reasons some commands "do shell script " (like sed -n '$=' file_name) in myscript.scpt does not work on Leopard either. It does not mean that they don't work if I run it right from Terminal, but only when I run it from my app. So I'm trying to find some other ways to solve my problem. Maybe it would be easier to get out if app is not active? But I'm newcomer about apple script, and need to solve this problem as quickly as can. |
Why go by feeling when you can test it? Performance can always be analyzed; don't make implementation decisions based on assumptions of performance. ;)
I also prefer -f because it's more explicit. You want to know if a file exists, and there is a reasonably fast way of doing it explicitly. No reason to spawn two processes instead of one, when one is the explicit version that is already fast. For what it's worth, if you use ls and the file doesn't exist, ls exits non-zero, which causes "do shell script" to throw an error that has to be caught with try/on error anyway. You don't really save any code. |
Quote:
|
Quote:
|
Quote:
Code:
ps -x | grep '/Address Book.app/' | wc -l |
I would recommend that the ps part be:
Code:
ps -ax -o commandAlso only outputs the command name so it has to do less digging in kernel data. and the grep part: Code:
grep '[A]larm Clock'Code:
ps -ax -o command|grep '[A]larm Clock'|wc -lotherwise it's the number of processes for that name |
See the various solutions suggested (for determining if a particular app is running) on DaringFireball.net: http://daringfireball.net/2006/10/processing_processes
See also the two versions of the app_running script on my Bash scripts page: http://hayne.net/MacDev/Bash/ |
Quote:
|
I did in such way:
tell application "Address Book" set itRuns to it is running if not (itRuns) then activate end if -- add some addresses if not (itRuns) then quit end if end tell And so with other apps. Main problem was to run these scripts from specific app that runs them under root. Now it's over. Thanks to all. |
Quote:
|
Quote:
|
This app is our installer that runs some tasks. And if some of them have to be performed under root (installing widgets), it performs all tasks under root.
This is bug that nobody will fix in near future, and we have to do workarounds. |
Quote:
:) |
Quote:
It sounds like you aren't using a standard installer package, either. Why not? Quote:
Quote:
|
Quote:
I mean bug in installer is that when one of the tasks requires higher permissions, all of the tasks are performed with these highest permissions. |
Quote:
Quote:
|
Quote:
Quote:
For example, installer has to perform such tasks: install app into /Applications, widget into /Library/Widgets, importer into /Library/Spotlight, music into ~/Music etc. and do some additional tasks: add installed music to iTunes. Installing widget requires authorization even if it runs under admin. And then all tasks are performed under root. But actually I just found that there is option in installer for each task to specify which permissions it requires. And if set to perform with lowest permissions it works fine. So it will be a good lesson for me. Anyway I will remember to not using Finder in apple scripts if possible and to use POSIX file. |
Quote:
Quote:
Quote:
To be candid, your director should understand that Apple's already written a great installer system that his company doesn't have to maintain, and that users are comfortable with because it's standard and easy to use. And it's probably better than what he had his people build. We're also generally more trusting of Apple's installer system, because it avoids problems like the one we're talking about. |
| All times are GMT -5. The time now is 05:54 AM. |
Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.
Site design © IDG Consumer & SMB; individuals retain copyright of their postings
but consent to the possible use of their material in other areas of IDG Consumer & SMB.