A little applescript help if you would please

Discussion in 'Mac Programming' started by NoSmokingBandit, Jun 28, 2010.

  1. NoSmokingBandit macrumors 68000

    NoSmokingBandit

    Joined:
    Apr 13, 2008
    #1
    I'm attempting to write an applescript, but i really dont know what i'm doing. I have the whole thing set up, but i need to be able to open a file in the same directory as the script without resorting to using its full path (ie /Users/Steve/... so on).

    Code:
    set sel_rom to (choose file with prompt "Select a Rom")
    
    set gfx_list to {"Glide", "Rice", "Arach"}
    set sel_gfx to (choose from list gfx_list with prompt "Select a GFX Plugin" without multiple selections allowed) as text
    
    if sel_gfx is "Glide" then
    	do shell script "./run_glide.sh " & sel_rom & ""
    end if
    if sel_gfx is "Arach" then
    	do shell script "./run_arach.sh " & sel_rom & ""
    end if
    if sel_gfx is "Rice" then
    	do shell script "./run_rice.sh " & sel_rom & ""
    end if
    
    
    
    So what i need to do is get the script to know that run_glide.sh (and the others) is in the same folder as the script itself. It seems as though the script always runs as if it is in "/", not the folder it actually is in.

    It cant be hard, i just dont know anything about this, lol.
     
  2. calderone macrumors 68040

    calderone

    Joined:
    Aug 28, 2009
    Location:
    Seattle
    #2
    This should work for you:

    Code:
    set scriptLoc to (path to me)
    set scriptLocPosix to POSIX path of scriptLoc
    set AppleScript's text item delimiters to "/"
    set parentDir to (items 1 thru -2 of text items of scriptLocPosix) as string
    set AppleScript's text item delimiters to ""
    
    set sel_rom to (choose file with prompt "Select a Rom")
    
    set gfx_list to {"Glide", "Rice", "Arach"}
    set sel_gfx to (choose from list gfx_list with prompt "Select a GFX Plugin" without multiple selections allowed) as text
    
    if sel_gfx is "Glide" then
    	do shell script parentDir & "/run_glide.sh " & sel_rom & ""
    end if
    if sel_gfx is "Arach" then
    	do shell script parentDir & "/run_arach.sh " & sel_rom & ""
    end if
    if sel_gfx is "Rice" then
    	do shell script parentDir & "/run_rice.sh " & sel_rom & ""
    end if
     
  3. NoSmokingBandit thread starter macrumors 68000

    NoSmokingBandit

    Joined:
    Apr 13, 2008
  4. Bill McEnaney macrumors 6502

    Joined:
    Apr 29, 2010
    #4
    Does AppleScript include a "case" statement or a "switch" statement?
     

Share This Page