• 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: "do shell" vs. Plain old AppleScript nomenclature
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: "do shell" vs. Plain old AppleScript nomenclature


  • Subject: Re: "do shell" vs. Plain old AppleScript nomenclature
  • From: Nigel Smith <email@hidden>
  • Date: Mon, 26 Jul 2004 16:47:07 +0100

On 26/7/04 15:17, "D. Mahaffy" <email@hidden> wrote:

> A hearty thanks!! to all who've responded! Some excellent suggestions...

Darren,

Each "do shell script" adds an overhead to your script -- you are, in
effect, asking another application to do some work, then waiting for its
reply. So you want to keep the number of "do shell script"s to a minimum.

Also, where dates and times are concerned, it is best to get the data once,
then process it. Your script could give a bogus result if, for example, you
called it just before midnight of the last day of a month -- you could have
"theMonth" from just before midnight, but the day and time from just after
in the new month...

So if all you want is to get:
the month (January, February...)
the day (Monday, Tuesday...)
the hour (1-12)
the minute (0-59)
morning or afternoon (AM/PM)

Then how about:

--start script
set dateString to do shell script "date +%B%n%A%n%I%n%M%n%p"
set theMonth to paragraph 1 of dateString
set theDay to paragraph 2 of dateString
set theHour to paragraph 3 of dateString
set theMinute to paragraph 4 of dateString
set amPm to paragraph 5 of dateString

return {theMonth, theDay, theHour, theMinute, amPm}
--end script

If you don't want the leading zero on hours < 10, replace
set theHour to paragraph 3 of dateString
...with
set theHour to paragraph 3 of dateString as number as text

If you want more items from the date, at the terms required in the shell
script, seperated by "%n" (which sperates them each by a newline), then get
the appropriate paragraph later on.

HTH,

Nigel
_______________________________________________
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.


References: 
 >Re: "do shell" vs. Plain old AppleScript nomenclature (From: "D. Mahaffy" <email@hidden>)

  • Prev by Date: Photoshop resize image
  • Next by Date: Creating a new header item in Mail
  • Previous by thread: Re: "do shell" vs. Plain old AppleScript nomenclature
  • Next by thread: Re: "do shell" vs. Plain old AppleScript nomenclature
  • Index(es):
    • Date
    • Thread