• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Hungry app
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hungry app


  • Subject: Re: Hungry app
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 08 Jan 2013 22:00:02 +1100

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.

Cheers,
-- 
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Follow-Ups:
    • Re: Hungry app
      • From: "koenig.yvan" <email@hidden>
References: 
 >Hungry app (From: Jörgen Stahle <email@hidden>)
 >Re: Hungry app (From: Jörgen Stahle <email@hidden>)
 >Re: Hungry app (From: Axel Luttgens <email@hidden>)
 >Re: Hungry app (From: Shane Stanley <email@hidden>)
 >Re: Hungry app (From: Axel Luttgens <email@hidden>)
 >Re: Hungry app (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Mail in Mt Lion
  • Next by Date: Re: Hungry app
  • Previous by thread: Re: Hungry app
  • Next by thread: Re: Hungry app
  • Index(es):
    • Date
    • Thread