• 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: Missing value
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Missing value


  • Subject: Re: Missing value
  • From: Jon Pugh <email@hidden>
  • Date: Sun, 28 Aug 2011 13:29:34 -0700

On Aug 28, 2011, at 1:10 PM, Ron Hunsinger wrote:
On Aug 28, 2011, at 12:10 PM, Christopher Stone wrote:
if appName ends with ".app" then
set shortAppName to text 1 thru ((offset of ".app" in appName) - 1) of appName

This use of offset is not robust. What if appName is "Nifty.appliance.app"?
If you know the extension (because you hard-coded it) you know its length and can hard-code that too.

if appName ends with ".app" then
set shortAppName to text 1 thru -5 of appName

If you can't hardcode the length, either because you didn't hard-code the extension or you want to minimize your use of magic constants:

if appName ends with anExtension then
set shortAppName to text 1 thru (-1 - length of anExtension) of appName

This is the kind of thing where my SmartString class shines:

tell SmartString
  setString(appName)
  set shortAppName to beforeString(".app")
end SmartString
if shortAppName = "" then set shortAppName to appName -- no .app extension

For example...

Jon

 _______________________________________________
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

References: 
 >Missing value (From: Robert Poland <email@hidden>)
 >Re: Missing value (From: Christopher Stone <email@hidden>)
 >Re: Missing value (From: Ron Hunsinger <email@hidden>)

  • Prev by Date: Re: Missing value
  • Next by Date: Re: Missing value
  • Previous by thread: Re: Missing value
  • Next by thread: Re: Missing value
  • Index(es):
    • Date
    • Thread