Page 1 of 2

Time Set Script Not Working

PostPosted: Sat Apr 21, 2018 8:43 pm
by ckeyes888
After upgrading to 10.12 this script, which set my time variables no longer works.

Code: Select all
set theDate to (current date) as string
set hourWord to word 5 of theDate as integer --hour
set minWord to word 6 of theDate as integer --minute

set apWord to word 8 of theDate --AM or PM
set theHour to hourWord * 100 + minWord

if (apWord = "PM" and hourWord ≠ 12) then set theHour to theHour + 1200
if (apWord = "AM" and hourWord = 12) then set theHour to theHour - 1200

-- add leading zero if necessary
set minWordString to minWord as string

set theLength to the length of minWordString
if theLength = 1 then
   set minWord to "0" & minWord as string
end if

set theClock to (hourWord as string) & ":" & minWord as string

set theDay to text 1 thru 3 of theDate

tell application "IndigoServer"
   set value of variable "TimeNow" to (current date) as string
   set value of variable "TimeNow2400" to theHour
   set value of variable "ClockTime" to theClock
   set value of variable "DayShort" to theDay
end tell


It returns this error:

Error script error: around characters 77 to 84
Error script error: Can’t make "at" into type integer. (-1700)

Appreciate any help with a fix.

Thanks,

carl

Re: Time Set Script Not Working

PostPosted: Sat Apr 21, 2018 9:32 pm
by ckeyes888
Curious, how are people setting time variables now?
Doubt it’s by using my above script.

Thanks,

Carl

Re: Time Set Script Not Working

PostPosted: Sun Apr 22, 2018 12:13 am
by howartp
Interesting question, and I think all the conversations about it are using AppleScript and variables.

This is crying out to be a plugin - and it would only take minutes to write (no pun intended).

Let me have a look.


Sent from my iPhone using Tapatalk Pro

Re: Time Set Script Not Working

PostPosted: Sun Apr 22, 2018 2:09 am
by howartp

Re: Time Set Script Not Working

PostPosted: Sun Apr 22, 2018 5:15 am
by jalves
ckeyes888 wrote:
Curious, how are people setting time variables now?

For current time I use a schedule that runs every minute. It puts the current time string into a variable called "Current_Time" with the format string "%l:%M %p"

Re: Time Set Script Not Working

PostPosted: Sun Apr 22, 2018 8:12 am
by ckeyes888
howartp wrote:
https://github.com/howartp84/ClockDisplay/releases/tag/1.0.0

Tadaa

Peter


Love the plugin! Maybe some way to remove the preceding 0? e.g. 07:27 AM to 7:27 AM

Thanks a bunch,

Carl

Re: Time Set Script Not Working

PostPosted: Sun Apr 22, 2018 8:14 am
by howartp
Definitely.


Sent from my iPhone using Tapatalk Pro

Re: Time Set Script Not Working

PostPosted: Sun Apr 22, 2018 3:27 pm
by ckeyes888
howartp wrote:
Definitely.

?

Carl


Sent from my iPhone using Tapatalk Pro

Re: Time Set Script Not Working

PostPosted: Sun Apr 22, 2018 3:37 pm
by howartp
Definitely will add ability to remove zero.

I intended it from the start, because PHP has both time values with and without, but Python only has time value natively.

Peter


Sent from my iPhone using Tapatalk Pro

Re: Time Set Script Not Working

PostPosted: Mon Apr 23, 2018 6:08 pm
by ckeyes888
Might also be nice to have the am pm in lowercase.
Maybe just me but I think it looks much better.

Carl

Re: Time Set Script Not Working

PostPosted: Mon Apr 23, 2018 8:31 pm
by howartp
I agree; Python’s defaults are poor in my opinion.

Will sort.


Sent from my iPhone using Tapatalk Pro

Re: Time Set Script Not Working

PostPosted: Tue Apr 24, 2018 10:22 am
by jay (support)
ckeyes888 wrote:
Curious, how are people setting time variables now?
Doubt it’s by using my above script.


Insert Timestamp into Variable

Re: Time Set Script Not Working

PostPosted: Tue Apr 24, 2018 10:25 am
by jay (support)
howartp wrote:
https://github.com/howartp84/ClockDisplay/releases/tag/1.0.0

Tadaa


Awesome README in Github! :wink:

Re: Time Set Script Not Working

PostPosted: Tue Apr 24, 2018 11:08 am
by ckeyes888
jay (support) wrote:
ckeyes888 wrote:
Curious, how are people setting time variables now?
Doubt it’s by using my above script.


Insert Timestamp into Variable


Great reference...thanks for posting.
Not seeing a way to not pad the time with a 0, or have a lowercase am pm.
Maybe I missed something?

Carl

Re: Time Set Script Not Working

PostPosted: Tue Apr 24, 2018 11:39 am
by jay (support)
%l (lowercase L) is a platform-dependent specifier to get the time without the 0 padding (pads with a space instead). So it'll work as long as Apple doesn't change the POSIX implementation that's used by Python.