You are not logged in.
Hi I would like to include in my detailed log of app the time stamp with milliseconds when a VerboseLog() handler is called.
At the moment I can write something like YYYYMMDD-HHMMSS but i miss the milliseconds.
Anyone has a solution using pure AppleScript or Asoc?
Stefano - Ame
Offline
I don't know of a way to do it in "pure" Applescript, but you can do it with a do shell script and Perl.
Applescript:
set UNIXtime to do shell script "perl -e 'use Time::HiRes qw(time); print time'"
Hackintosh built February, 2012 | Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb
Offline
With ASObjC:
Applescript:
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
set now to current application's class "NSDate"'s |date|()
set dateFormatter to current application's class "NSDateFormatter"'s new()
tell dateFormatter to setDateFormat:("yyyyMMdd-HHmmss.SSS")
set timeStamp to (dateFormatter's stringFromDate:(now)) as text
However, I don't imagine the clock on your computer will be that accurately set.
NG
Offline
Hi Nigel,
W o n d e r f u l ! ! !
Exactly what I need. Thank you!!!
Stefano
Offline
With AppleScript Toolbox:
Applescript:
AST format date "yyyyMMdd-HHmmss.SSS"
Offline
With Python:
Applescript:
do shell script "
/usr/bin/python <<END
from datetime import datetime
print datetime.now()
END"
Hackintosh built February, 2012 | Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb
Offline
Or if you want the Python to spit out the requested formatting instead of doing it in Applescript (Python formatting code is shorter)
Applescript:
do shell script "
/usr/bin/python <<END
from datetime import datetime
now = datetime.now()
print '%04d%02d%02d-%02d%02d%02d.%d' % (now.year,now.month, now.day,now.hour,now.minute,now.second, int(round((float(now.microsecond)/1000), 0)))
END"
This is rounding the fractional seconds to three decimal places (milliseconds) as requested.
If you want the full microseconds:
Applescript:
do shell script "
/usr/bin/python <<END
from datetime import datetime
now = datetime.now()
print '%04d%02d%02d-%02d%02d%02d.%d' % (now.year,now.month, now.day,now.hour,now.minute,now.second, now.microsecond)
END"
Hackintosh built February, 2012 | Mac OS Sierra
GIGABYTE GA-Z68X-UD3H-B3 | Core i5 2500k | 16 GB DDR3 | GIGABYTE Geforce 1050 TI 4GB
250 GB Samsung 850 EVO | 4 TB RAID
Dell Ultrasharp U3011 | Dell Ultrasharp 2007FPb
Offline