On 08/01/2013, at 9:14 PM, Jörgen Stahle <email@hidden> wrote:
Maybe there is a better way of doing it. Is it? It works with Finder as well, but "System Events" is used anyway int his script to check if the app is a startup item. In the past I sometimes used System Events instead of Finder, because Finder at that time was not multithreaded - thoug shell scripting is more often a better alternative. So how would you do this?
Your run handler was this:
on run my startWeb() global myPath, gMyPosixPath, gMyName tell application "System Events" set myPath to (path to me) set gMyPosixPath to POSIX path of myPath set gMyName to (name of myPath) set AppleScript's text item delimiters to "." set gMyName to first text item of gMyName set AppleScript's text item delimiters to "" end tell my assureMeLoginItem() do shell script "defaults write " & prefsDomain & space & myNameKey & space & the quoted form of gMyName end run
You shouldn't call scripting additions within "tell app..." blocks, and all you're using it for is to get a file's name. You could do this instead:
on run my startWeb() global myPath, gMyPosixPath, gMyName set myPath to (path to me) set gMyPosixPath to POSIX path of myPath set saveTID to AppleScript's text item delimiters set AppleScript's text item delimiters to {"/"} set gMyName to text item -1 of gMyPosixPath set AppleScript's text item delimiters to "." set gMyName to first text item of gMyName set AppleScript's text item delimiters to saveTID my assureMeLoginItem() do shell script "defaults write " & prefsDomain & space & myNameKey & space & the quoted form of gMyName end run
My preference would be to declare the globals outside the run handler, along with the properties, but that's probably a simple matter of taste.
|