set path_ to (path to me as string)
set thePath to path_ as alias
set slash_ to (ASCII character 34)
set change_system_variable_command to "PSIDATADIR=" & slash_ & POSIX path of thePath & slash_
tell application "Terminal"
do script change_system_variable_command
end tell
The script somehow works.
One problem left. “path to me” seems to return not only the folder the script is located in but as well the filename of the script (in my case it returns /Volumes/psi_2/psi-script.app with psi-skript.app as the scripts name). How do I remove the filename from this variable and just get the folder?
This little script works for me when I save it as an application (otherwise you just get the path to the Script Editor):
set myPath to POSIX path of (path to me as string) -- gets it in "/" form
set ASTID to AppleScript's text item delimiters -- save 'em
set AppleScript's text item delimiters to "/"
set theFolder to (text 1 thru text item -2 of myPath) & "/" as Unicode text
set AppleScript's text item delimiters to ASTID -- restore 'em
display dialog theFolder -- or whatever
Another way uses the Finder’s “container” term (but the other one is faster):
set myPath to path to me
tell application "Finder"
set myFolder to (container of myPath) as string
end tell
-- returns the path to the folder containing your script.
-- You can then append
-- another file name, or use it as an alias.
set d to text item delimiters
set text item delimiters to "/"
set f to (POSIX path of (path to me))'s text 1 thru text item -3 & "/"
set text item delimiters to d
display dialog f
set path_ to (path to me)
tell application "Finder"
set theFolder to (container of item path_)
end tell
set thePOSIXFolder to ((POSIX path of (theFolder as alias)) as string)