Monday, May 29, 2017

#1 2006-05-29 04:21:30 pm

Spock
Member
Registered: 2006-03-24
Posts: 24

TickCount (how can I get time more precise than one second?)

Hi!

In the developer documentation there is the file file:///Developer/ADC%20Reference%20Lib … rence.html
In this file a function TickCount is described:

TickCount

Obtains the current number of ticks (a tick is approximately 1/60 of a second) since the system last started up.

UInt32 TickCount ();

Availability:
Available in CarbonLib 1.0 and later when running Mac OS 8.1 or later.
Available in Mac OS X 10.0 and later.

Declared In
OSUtils.h

How can I use this function from within an ASS application?

I have tried

Applescript:

set theTicks to call method "TickCount"

but this does not work.

thanks for help

Offline

 

#2 2006-05-29 04:26:39 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4658

Re: TickCount (how can I get time more precise than one second?)

I use GetMilliSec 1.0.1 found here. It returns the time since the last startup in milliseconds, so to time something you:

Applescript:

set t1 to GetMilliSec
-- do stuff
set t2 to GetMillisec
t2 - t1


iMac running OS X 10.11.6

Offline

 

#3 2006-05-29 04:35:03 pm

Spock
Member
Registered: 2006-03-24
Posts: 24

Re: TickCount (how can I get time more precise than one second?)

Can I include GetMilliSec in an ASS application, without the need to install it on every target computer?

Offline

 

#4 2006-05-29 04:45:01 pm

Bruce Phillips
Administrator
Registered: 2004-07-15
Posts: 2649

Re: TickCount (how can I get time more precise than one second?)

Spock wrote:

Can I include GetMilliSec in an ASS application, without the need to install it on every target computer?

I think you can include the actual Scripting Addition to the application bundle…

Offline

 

#5 2006-05-29 06:11:10 pm

Adam Bell
Administrator
From: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4658

Re: TickCount (how can I get time more precise than one second?)

Spock wrote:

Can I include GetMilliSec in an ASS application, without the need to install it on every target computer?

It's an osax. I suspect it can be included in the bundle and since it's free, I suspect that's acceptable. I haven't done it myself.


iMac running OS X 10.11.6

Offline

 

#6 2006-05-29 07:43:53 pm

kel
Member
Registered: 2002-11-19
Posts: 2031

Re: TickCount (how can I get time more precise than one second?)

Hi,

You can also use Jon's Commands for ticks or unix. Here's an example of python:

Applescript:


set t to "import time
print time.time()
"

set new_t to (ReplaceText(return, ASCII character 10, t))
set t_py to quoted form of new_t
set x to do shell script "python -c " & t_py
delay 5
set y to do shell script "python -c " & t_py
set d to (y as number) - (x as number)
set c to (round (d * 100) rounding down) / 100
{x, y, d, c}
--
-- search, replace, the text t
on ReplaceText(s, r, t)
   set dtid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to {s}
   set t_list to text items of t
   set AppleScript's text item delimiters to {r}
   set new_t to t_list as string
   set AppleScript's text item delimiters to dtid
   return new_t
end ReplaceText

On my computer, the time module returns down to 100ths of a second. The results are usually off by 6 to 9 hundredths of a second due to the shell call.

Jon's Commands is pretty accurate.

gl,


Kel

Offline

 

#7 2006-05-30 12:23:30 am

Mikey-San
Member
Registered: 2005-07-13
Posts: 509

Re: TickCount (how can I get time more precise than one second?)

Spock wrote:

Hi!

In the developer documentation there is the file file:///Developer/ADC%20Reference%20Lib … rence.html
In this file a function TickCount is described:

TickCount

Obtains the current number of ticks (a tick is approximately 1/60 of a second) since the system last started up.

UInt32 TickCount ();

Availability:
Available in CarbonLib 1.0 and later when running Mac OS 8.1 or later.
Available in Mac OS X 10.0 and later.

Declared In
OSUtils.h

How can I use this function from within an ASS application?

I have tried

Applescript:

set theTicks to call method "TickCount"

but this does not work.

thanks for help

Others have already provided a solution, but I wanted to answer this question specifically.

C functions can't be called directly from Studio. You need to wrap them in a Cocoa method and call that instead. Off the top of my head, you could add this to a new class in your project:

+ (NSString *)getTickCount
{
UInt32 ms = TickCount();
return [[NSNumber numberWithInt:ms] stringValue];
}

That will return a text string that is the number of ticks since system startup.

And then call that from your script with "call method":

Applescript:

set t to (call method "getTickCount" of class "YourClass")

Note: This hasn't been tested. I just jotted it down off the top of my head to give you an idea of what's involved with using C functions in AppleScript Studio.

Last edited by Mikey-San (2006-05-30 12:25:25 am)

Offline

 

#8 2006-05-30 12:27:08 am

Spock
Member
Registered: 2006-03-24
Posts: 24

Re: TickCount (how can I get time more precise than one second?)

Thank you (all of you) for your answers!

Offline

 

#9 2006-05-30 03:20:01 am

kel
Member
Registered: 2002-11-19
Posts: 2031

Re: TickCount (how can I get time more precise than one second?)

Hi,

UNIX experts like Mikey-San wrote that you should add the directory that the unix command resides in. Here's the correction:

Applescript:


set t to "import time
print time.time()
"

set new_t to (ReplaceText(return, ASCII character 10, t))
set t_py to quoted form of new_t
set x to do shell script "/usr/bin/python -c " & t_py
delay 5
set y to do shell script "/usr/bin/python -c " & t_py
set d to (y as number) - (x as number)
set c to (round (d * 100) rounding down) / 100
{x, y, d, c}
--
-- search, replace, the text t
on ReplaceText(s, r, t)
   set dtid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to {s}
   set t_list to text items of t
   set AppleScript's text item delimiters to {r}
   set new_t to t_list as string
   set AppleScript's text item delimiters to dtid
   return new_t
end ReplaceText

gl,


Kel

Offline

 

#10 2006-05-30 04:04:51 am

julifos
Administrator
From: Malasaña, Madrid
Registered: 2002-11-20
Posts: 2014

Re: TickCount (how can I get time more precise than one second?)

If you're interested only in measuring time between different actions, I think NSDate methods are accurate enough. For example:

Applescript:

set t1 to (call method "timeIntervalSinceReferenceDate" of class "NSDate")
delay 1
set t2 to (call method "timeIntervalSinceReferenceDate" of class "NSDate")

t2 - t1 --> around 1. Ie: 0.996235013008, 1.002915978432, ...

If you're interested really in OS uptime, you can use the various methods exposed before tongue

Offline

 

#11 2017-01-24 06:22:45 pm

jean.o.matic
Member
From: Montréal, Québec, Canada
Registered: 2009-10-04
Posts: 12

Re: TickCount (how can I get time more precise than one second?)

From Yosemite and up this should work — tested on El Capitan:
Important: the GetTick script should be last part of your code or script won't compile. You can also save it and use it in a script library.

Applescript:

set t1 to GetTick's Now()
delay 1
set t2 to GetTick's Now()
t2 - t1

script GetTick
   use framework "Foundation" --> for more precise timing calculations
   on Now()
       return (current application's NSDate's timeIntervalSinceReferenceDate) as real
   end Now
end script

--> 1.001203000546

Last edited by jean.o.matic (2017-01-25 05:53:20 pm)


______________________
Jean.O.matiC
Montréal, Québec, Canada

Offline

 

#12 2017-01-25 04:43:43 am

DJ Bazzie Wazzie
Member
From: the Netherlands
Registered: 2004-10-20
Posts: 2621

Re: TickCount (how can I get time more precise than one second?)

Does ASObjC work in AppleScript-Studio environment in Yosemite? Running some old AppleScript-Studio applications in Sierra but wasn't able to run ASObjC code in it.

Offline

 

#13 2017-01-25 06:07:38 pm

jean.o.matic
Member
From: Montréal, Québec, Canada
Registered: 2009-10-04
Posts: 12

Re: TickCount (how can I get time more precise than one second?)

Hi!
I did not do much scripting in Yosemite, Shane Stanley would be your best resource on this matter
Jean.O.matic


______________________
Jean.O.matiC
Montréal, Québec, Canada

Offline

 

Board footer

Powered by FluxBB

[ Generated in 0.050 seconds, 10 queries executed ]

RSS (new topics) RSS (active topics)