• 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: [OT] Shell scripting
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [OT] Shell scripting


  • Subject: Re: [OT] Shell scripting
  • From: Nigel Garvey <email@hidden>
  • Date: Sun, 28 Dec 2003 11:55:30 +0000

Reinhold Penner wrote on Fri, 26 Dec 2003 15:22:14 -1000:

>I was wondering if there is a shell way to apply the formatting to an
>arbitrary date string. For example get the creation/modification date
>of a file and format that as easily as below.
>
>-Reinhold
>
>On Dec 26, 2003, at 6:51, John W. Baxter wrote:

>> echo "AppleFileServer restarted by autoAfpCheck at `date +%H:%M\ on\
>> %Y-%m-%d`"
>>
>> Which gives
>> AppleFileServer restarted by autoAfpCheck at 08:46 on 2003-12-26

I think Paul's and Marc's replies have shown that while it's possible to
use shell scripting for this, it's far from being the best tool for the
job. Apart from the comparative slowness of the shell script itself, the
amount of preparatory work required beforehand in AppleScript (including
a number-to-string conversion) is more than is required to do the whole
job in AppleScript anyway.

on timeOnDateStr(ASDate)
set {year:y, day:d, time:t} to ASDate
copy ASDate to b
set b's month to January

tell (10000 + t div hours * 100 + t mod hours div minutes) as string
set shortTime to text 2 thru 3 & ":" & text 4 thru 5
end tell
tell (y * 10000 + (b - 2500000 - ASDate) div -2500000 * 100 + d) as
string
set shortDate to text 1 thru 4 & "-" & text 5 thru 6 & "-" & text 7
thru 8
end tell

return shortTime & " on " & shortDate
end timeOnDateStr

set modDate to date "Thursday, 27 November 2003 08:37:26"
set str to "File last modified at " & timeOnDateStr(modDate)
--> "File last modified at 08:37 on 2003-11-27"


Sorry to keep arguing AppleScript's superiority at date handling.

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

  • Prev by Date: Re: Open Dialog via filename extension?
  • Next by Date: Re: Open Dialog via filename extension?
  • Previous by thread: Re: [OT] Shell scripting
  • Next by thread: Open Dialog via filename extension?
  • Index(es):
    • Date
    • Thread