• 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: Removable Disks (wrapping code)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Removable Disks (wrapping code)


  • Subject: Re: Removable Disks (wrapping code)
  • From: Arthur Knapp <email@hidden>
  • Date: Tue, 11 Nov 2003 09:21:16 -0500

From: email@hidden (Christopher Rosado)
Subject: Re: Removable Disks (wrapping code)
Date: Mon, 10 Nov 2003 12:48:30 -0500

if month of (current date) is January then set newMonth to "01"
if month of (current date) is February then set newMonth to "02"

Hi. I'm sure this works fine, but I just wanted to point out that repeatedly calling a scripting addition can be a bit slow. Why not save it to a variable:

set current_date to current date

Secondly, you want to use "else if" statements. Consider, if the month happens to be January, then you end up making 11 unnessesary "if" tests, where as this construction:

set thisMonth to month of current_date

if ( thisMonth = January ) then
set newMonth to "01"
else if ( thisMonth = February ) then

ensures that once you've hit the right month, the other "if" tests aren't performed.

Of course, under Panther, you can now coerce a month constant to an integer:

set monthNum to thisMonth as integer

Pre-Panther, you can use the Greatest AppleScript Ever Written: :)

-- Emmanuel Livy's "French Vanilla" method for month numbers, optimised by Richard Hartman.
-- "English Fudge" version by NG (immune to a Mac OS bug that affects dates before 1904).
copy theDate to b
set b's month to January
set monthNum to (b - 2500000 - theDate) div -2500000

You could then use this old favorite:

set newMonth to ("0" & monthNum)'s text -2 thru -1


{ Arthur J. Knapp;
<mailto:email@hidden>;

What...? Oh...!
}
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Follow-Ups:
    • Re: Removable Disks (wrapping code)
      • From: "John W. Baxter" <email@hidden>
  • Prev by Date: Re: Removable Disks (wrapping code)
  • Next by Date: Re: weird UI scripting problems.
  • Previous by thread: Re: Removable Disks (wrapping code)
  • Next by thread: Re: Removable Disks (wrapping code)
  • Index(es):
    • Date
    • Thread