Follow us on...
Follow us on Twitter Follow us on Facebook
Register
Page 1 of 2 12 LastLast
Results 1 to 8 of 12
  1. #1
    bill_gates_sux is offline Registered User
    Join Date
    Jul 2002
    Location
    Ruffway, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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.

  2. #2
    voice-'s Avatar
    voice- is offline Registered User
    Join Date
    Oct 2001
    Location
    Arendal, Norway
    Posts
    1,818
    Thanks
    2
    Thanked 1 Time in 1 Post
    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

  3. #3
    bill_gates_sux is offline Registered User
    Join Date
    Jul 2002
    Location
    Ruffway, USA
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  4. #4
    dsnyder is offline Registered User
    Join Date
    Sep 2000
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by dsnyder; July 5th, 2002 at 01:08 PM.

  5. #5
    Trip's Avatar
    Trip is offline Registered User
    Join Date
    Sep 2001
    Location
    Utah
    Posts
    3,266
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  6. #6
    dsnyder is offline Registered User
    Join Date
    Sep 2000
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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.

  7. #7
    Trip's Avatar
    Trip is offline Registered User
    Join Date
    Sep 2001
    Location
    Utah
    Posts
    3,266
    Thanks
    0
    Thanked 1 Time in 1 Post
    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.

  8. #8
    dsnyder is offline Registered User
    Join Date
    Sep 2000
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. AppleScript front end to a shell script?
    By meancode in forum Mac OS X System & Mac Software
    Replies: 0
    Last Post: March 17th, 2002, 08:25 PM
  2. Any suggestions for writing HTML?
    By chemistry_geek in forum Design & Media
    Replies: 3
    Last Post: January 2nd, 2002, 04:00 PM
  3. AppleScript in the Finder in 10.1 (Spring-Loaded Folders???)
    By simX in forum Apple News, Rumors & Discussion
    Replies: 1
    Last Post: October 14th, 2001, 09:27 PM
  4. AppleScript Studio? Is this our new HyperCard?
    By rharder in forum Apple News, Rumors & Discussion
    Replies: 5
    Last Post: September 27th, 2001, 11:44 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •