A strange request - but I'm trying to work out how long I spend with a certain app open. Is there any way that I can do this, without using a third party app?
You can try this :A strange request - but I'm trying to work out how long I spend with a certain app open. Is there any way that I can do this, without using a third party app?
global startDate
set startDate to (current date)
tell application "VLC" to activate
on idle
if application "VLC" is not running then
set stopDate to (current date)
set timeInSec to stopDate - startDate
set timePassed to do shell script "python -c 'import datetime; print str(datetime.timedelta(seconds=" & timeInSec & "))'"
display notification "The application \"VLC\" ran for " & timePassed & " in h:mm:ss."
tell me to quit
end if
return 1
end idle
You're welcome.
I hate to be a pain but, is there anyway that I will add up all the number of hours and minutes I have used the application for?
Say I use the app for 30 minutes one day, when I quit the app the script will tell me that the app has been running for 30 minutes. Say the next day I use it for 15 minutes - can I get the script to tell me that the app has been running for a total of 45 minutes?
Many thanks!
property totalTimeInSec : 0
global startDate
set startDate to (current date)
tell application "VLC" to activate
on idle
if application "VLC" is not running then
set stopDate to (current date)
set timeInSec to stopDate - startDate
set totalTimeInSec to totalTimeInSec + timeInSec
set timePassed to do shell script "python -c 'import datetime; print str(datetime.timedelta(seconds=" & timeInSec & "))'"
set totalTimePassed to do shell script "python -c 'import datetime; print str(datetime.timedelta(seconds=" & totalTimeInSec & "))'"
display notification "Application \"VLC\" ran for " & timePassed & return & "Total: " & totalTimePassed
tell me to quit
end if
return 1
end idle
Try this :
Code:property totalTimeInSec : 0 global startDate set startDate to (current date) tell application "VLC" to activate on idle if application "VLC" is not running then set stopDate to (current date) set timeInSec to stopDate - startDate set totalTimeInSec to totalTimeInSec + timeInSec set timePassed to do shell script "python -c 'import datetime; print str(datetime.timedelta(seconds=" & timeInSec & "))'" set totalTimePassed to do shell script "python -c 'import datetime; print str(datetime.timedelta(seconds=" & totalTimeInSec & "))'" display notification "Application \"VLC\" ran for " & timePassed & return & "Total: " & totalTimePassed tell me to quit end if return 1 end idle
No problem, glad to help. A word of caution though! The value set by a property definition is not reset each time the script is run; instead, it persists until the script is recompiled. Meaning you've been using the script for a few days and decide to change something then the value will be reset to the initial value for the property eg 0. Might I ask what app you're monitoring and do you expect the value to go beyond 24 Hours?Once again, Kryten2, many thanks!
No problem, glad to help. A word of caution though! The value set by a property definition is not reset each time the script is run; instead, it persists until the script is recompiled. Meaning you've been using the script for a few days and decide to change something then the value will be reset to the initial value for the property eg 0. Might I ask what app you're monitoring and do you expect the value to go beyond 24 Hours?