Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Enthusiast Zone > Classic Macs and Mac OS > Apple Script: Open Apps and Startup Disk

Apple Script: Open Apps and Startup Disk
Thread Tools
macvillage.net
Addicted to MacNN
Join Date: Sep 2000
Status: Offline
Reply With Quote
Aug 31, 2001, 07:45 PM
 
2 questions for an AS pro:

1. I currently have a script as follows:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>
set theFolder to <font color = red>"Macintosh HD:System Folderreferences:"</font>
</font>[/code]

Now not everyone has their startup disk titled "Macintosh HD" does anyone know how to do it so that no matter what the name of the startup disk is, it will set "theFolder" to the path to preferences?


I though it involved "startup disk" but that didn't work when I replaced Macintosh HD" with "startup disk" anyone?

2. I currently have two scripts. One works with one program, and one works with that programs compeditor (keeping the name supressed to avoid a debate over what is better.)

How can I create a script that will see what program(s) is/are currently running and run the appropriate sub-script based on what is already running? But if both are running, it brings up a dialog box.

It would need to see what is runnig If both run display dialog "can't run both"
If app1 is running then "run app1()"

if app2 is running then "run app2()"

Anyone know? I have been trying to figure it out, but I am blank.

Lastly, does anyone know of a Mac OS X method? Is it the same as for Mac OS 9?
     
acur128
Junior Member
Join Date: May 2001
Status: Offline
Reply With Quote
Aug 31, 2001, 09:02 PM
 
1. I guess there are a few ways.. if you just want to get the preferences folder as an alias path, you could use (path to preferences folder); if you wanted a Finder reference to it for copying/moving files, you could ask the Finder for its reference format (usually not necessary, since in most situations the Finder recognizes both forms):
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>set theFolder to (path to preferences folder)
-- alias <font color = red>"Macintosh HD:System Folderreferences:"</font>

tell application <font color = red>"Finder"</font> to set theFolder to preferences folder
-- folder <font color = red>"Preferences"</font> of folder <font color = red>"System Folder"</font> of startup disk of application <font color = red>"Finder"</font></font>[/code]
The Finder can also coerce its format into a string or an alias path by adding as string or as alias:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>tell application <font color = red>"Finder"</font> to set theFolder to preferences folder as string
-- <font color = red>"Macintosh HD:System Folderreferences:"</font></font>[/code]
For Finder functions, usually either method works, but if one doesn't for some reason, the other should.

2. In OS 9, using the Finder's process class calls up the refs to all running apps, so something like this should do it:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>tell app <font color = red>"Finder"</font> to set processList to name of processes
<font color = green>if</font> <font color = red>"Internet Explorer"</font> is in processList then
<font color = green>if</font> <font color = red>"Netscape Communicator� <font color = blue>4.7</font>"</font> is in processList then
display dialog <font color = red>"Can't run both!"</font>
<font color = green>else</font>
display dialog <font color = red>"Running Internet Explorer subscript..."</font> giving up after <font color = blue>2</font>
do_ExplorerStuff()
end <font color = green>if</font>
<font color = green>else</font> <font color = green>if</font> <font color = red>"Netscape Communicator� <font color = blue>4.7</font>"</font> is in processList then
display dialog <font color = red>"Running Netscape Comm. subscript..."</font> giving up after <font color = blue>2</font>
do_CommunicatorStuff()
end <font color = green>if</font>

on do_ExplorerStuff()
-- <font color = green>do</font> Explorer stuff
end do_ExplorerStuff

on do_CommunicatorStuff()
-- <font color = green>do</font> Communicator stuff
end do_CommunicatorStuff</font>[/code]
Unfortunately, there's no equivalent in plain old Applescript for OS X yet (the Finder doesn't understand processes)... maybe in the 10.1 final...
But a scripting addition that can send commands to the shell, a UNIX process list (ps -wwx or something similar) can be generated. Although a messy listing, the name of the apps can be picked out of the list. With the KinderShell scripting addition, something like this should work:
<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>set processList to list processes -- list processes runs ps -wwx
<font color = green>if</font> <font color = red>"Internet Explorer"</font> is in processList then display dialog <font color = red>"IE is running"</font></font>[/code]
There's also a Classic scripting addition set called Script Tools 1.3.6 (formerly LNS Scripting Additions) from Late Night Software Ltd. - available here that has a scripting addition called "Processes" that also uses "list processes" to get a list of running apps without the Finder. So, with both "Processes" installed in OS 9 & "KinderShell" installed in OS X, one could conceivably use the same script in both OS 9 & OS X... just a thought. It's possible the 10.1 Finder could provide a cleaner way.

edit: oops... list processes was from a scripting addition called "Processes" (see above)... the Finder's processes class will do the same. & UBB code... ugh!

[ 08-31-2001: Message edited by: acur128 ]
     
macvillage.net  (op)
Addicted to MacNN
Join Date: Sep 2000
Status: Offline
Reply With Quote
Aug 31, 2001, 09:30 PM
 
All works except:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>set processList to list processes</font>[/code]
variable processes is not defined.

Thanks
     
acur128
Junior Member
Join Date: May 2001
Status: Offline
Reply With Quote
Aug 31, 2001, 10:05 PM
 
Sorry... too many scripting additions... the "list processes" was from a "Processes" scripting addition from a set of osax called Script Tools from Late Night Software. The Finder can get processes in OS 9 but not OS X... that's what I was thinking of.
I've edited the first post with the correct info!

edit: reedited the first post... while filtering out all the markup, also filtered out some quotes. And the correct Finder usage would be:
tell application "Finder" to set processList to name of processes
... should work now with input of the correct app names

[ 08-31-2001: Message edited by: acur128 ]
     
   
Thread Tools
 
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Top
Privacy Policy
All times are GMT -4. The time now is 07:36 PM.
All contents of these forums © 1995-2017 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.8 © 2000-2017, Jelsoft Enterprises Ltd.,