Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

NoSmokingBandit

macrumors 68000
Original poster
Apr 13, 2008
1,579
3
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.
 
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
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.