I need help with an AppleScript I'm writing...

bill_gates_sux

Registered
I'm trying to write an AppleScript that will help me out when I start up my computer. Currently, I have a script that I wrote to only launch AOL. I now want to write a script that will give me a choice between three applications (they are all on my Desktop, just to make things easier). I followed the commands in the AS Dictionary, but it didn't work. Could anyone skilled in creating AppleScripts help me out and make it for me, please.

I would like it to display a dialog box that says: "Which application would ou like me to open?" and have buttons for these three answers: "America Online 5.0", "AppleWorks 6.1.2", "iTunes".

I would greatly appreciate any and all help.
 
I know this guy(Poor selection for a name, Eric) and I know he's in OS 9 if that makes things any clearer. I don't know for sure, but I can imagine that being a nice piece of info
 
Originally posted by voice-
Poor selection for a name, Eric

Couldn't think of anything more appropriate for a Mac forum. I followed every command in the Dictionary but I got a ton of errors. Maybe it's just me.
 
I wrote an Applescript a while back which effectively does exactly what you want. I was distributing a CD with a variety of different software installers on it. When running the script, the user would be presented with a list of software included on the CD. The use can then choose the application they want to install, and the script will launch that installer. I think you can probably modify this to meet your needs. I designed it so it will read in a file with the name to display for each application, and the name of the installer itself. The syntax for this file is a bit stupid. It is a text file, which should have first the name you want to display, then a semicolon (;) and carriage return, and then the name of the application you want to run followed by a semicolon and carriage return. Repeat this for each application, so you will have a list like:

AOL;
America Online;
iTunes;
iTunes;
AppleWorks;
AppleWorks 6.2.3;

A carriage return after the last line is important. You could probably even modify it to do away with the need for two entries for each app. With the installers I was dealing with, the name of the installers did not really make it obvious what the program was (e.g. the users this would targeted at wouldn't know that NAV80 was Norton Antivirus). The advantage of doing this with a file is that you won't have to modifu and recompile your script of if you want to launch more applications in the future. Just fire up SimpleText and add some lines to the text file.

Let me know if you need more explanation of anything here.

Here it is (I've added comments in the parts I think you will need to change:

-- initialize variables
set i to 1
set AppList to {}
set InstList to {}

-- change delimiter to parse our file
set AppleScript's text item delimiters to ";" & (ASCII character 13)

-- copy the text of the file into a variable
--change two lines below to match location of your text file
open for access file "Network Clients Installer:Installer List"
set raw_text to read file "Network Clients Installer:Installer List"

-- seperate each item into a list
set text_list to text items of raw_text

-- divide up the list: we want a list of names to display and a list of associated installers
set n to the number of items in text_list
repeat while i < n
set AppList to AppList & item i of text_list
set InstList to InstList & item (i + 1) of text_list
-- return AppList
set i to (i + 2)
end repeat

-- ask user which application to install, save this is "selected_app"
set the dialog_result to ¬
choose from list AppList with prompt "Please choose the software you would like to install"
if the dialog_result is false then
return "action cancelled by user"
else
set selected_app to the first item of the dialog_result
end if

-- find the installer associated with "selected_app"
repeat with i from 1 to the count of the AppList
if item i of the AppList is the selected_app then
set inst to item i of the InstList
exit repeat
end if

end repeat

-- run the installer
tell application "Finder"
activate
--you will need to change this to match the location of your stuff. probably
--open file (inst as string) of Desktop
open file (inst as string) of folder "Software Installers" of disk "Network Clients Installer"

end tell
 
There is a much, much, much shorter way to do it, but I don't know all the correct variables and such, it has to do with displaying a message box with 3 buttons. Each button has a different title, when one button is pressed the script shutsdown and launches the program.
 
I'm sure there is. But, this is the first AppleScript I ever wrote, and I never had the time to go back and make it more efficient. And hey, it works.
 
Something like this:

display dialog "Select program to launch:" buttons {"AOL", "iTunes", "AppleWorks"} default button 1

if the button returned of the result is "AOL" then
tell application "America Online"
run
end tell
else if the button returned of the result is "iTunes" then
tell application "iTunes"
run
end tell
else if the button returned of the result is "AppleWorks" then
tell application "Carracho 1.0b6r5"
run
end tell
end if

Ok, that should work. But you'll probably have to re-name the "Application names" that are there...like AppleWorks should be changed to something like: "Appleworks 1.2.0" or whatever the application is actually called.

Oh and, no problem. :)
 
That's really cool. I'm curious about a couple of things though. Does AppleScript just "automagically" find the applications? Will it waste lots of time searching for them or will it just know where they are? And can it "automagically" find stuff on removeable disks? I don't see how this works since there is nothing equivalent to the registry in Windows. Also, do the apps have to be AppleScript savvy to be able to accept the "run" event?

Thanks,

Dave
 
Well, if you get the application program names 100% correct (e.x. "iTunes" not "iTunes 1.0") then AppleScript will automatically find it. I don't know how to explain it...like...your HD's name has to be exact to get data from it. Something like that, so if you don't type it right AppleScript will ask you where the program is located.

And a wide majority of programs accept the "run" event, but I have ran across a few that don't. :(
 
Trip, I copy-and-pasted the script you wrote, and everything worked perfectly (aftre I corrected the little 'AppleWorks opens Carracho' mistake.) dsnyder, I tried modifying your script, but I'm not good enough at writing AS's to follow all of your comments.
 
Really glad I found this thread. I think this is the answer I am looking for. I'm clueless when it comes to Applescript but here's what I'm trying to do:

I have an old 8500 that I want to hook up to my TV and have networked to my main Mac in another room for access to Video/Audio files. I just wanted to build a simple interface to launch Quicktime and iTunes. I wanted to know if I can edit Trip's script to be able to do the following:

1) The buttons would be bigger/have different color

2) The button window would take up the whole screen and would hide the finder and menu bar

3) The button window would stay open the whole time (would not quit after launching an app)

I'd also like to write a script where I could hit the "Open Quicktime" button and QT would launch and would default to an Open dialog box to choose various video files in a desgnated folder. After the file is chosen, it would then load it and play full screen. After the video is done playing, QT would then quit and go back to the button window.

Would this be possible? Any and all help is appreciated. Thanks.
 
Back
Top