GetMyLocation

This handler returns the location (the upper folder) where the first document in ScriptEditor 1.9 and 2.0 (v36) is stored on the hard drive instead of returning the Editor’s path when using ‘path to me’ within a script.

This is a workaround for the missing ‘path to me referrs to document’ feature in Apple’s ScriptEditor.

OS version: OS X

--
on run
	return GetMyLocation()
end run

--
on GetMyLocation()
	tell me
		set StoreLocation to (path of document 1)
	end tell
	set FilePath to (characters 1 thru -2 of ((path to startup disk) as string) as string) & StoreLocation
	set FilePath to getParFolPath(SaR(FilePath, "/", ":"))
	return FilePath
end GetMyLocation
--
on SaR(aText, asearch, areplace)
	try
		set oldAstid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to asearch
		set a_text to every text item of aText
		set AppleScript's text item delimiters to areplace
		set a_text to (every text item of a_text) as string
		set AppleScript's text item delimiters to oldAstid
		return a_text
	on error
		return ""
	end try
end SaR
--
on getParFolPath(the_filepath)
	try
		set the_filepath to the_filepath as string
		if the_filepath ends with ":" then set the_filepath to (characters 1 through -2 of the_filepath) as string
		set x to the offset of ":" in (the reverse of every character of the_filepath) as string
		set templ to (characters 1 thru -(x) of the_filepath) as string
	on error
		set templ to the_filepath
	end try
	return templ
end getParFolPath
--