Time Set Script Not Working

Posted on
Sat Apr 21, 2018 8:43 pm
ckeyes888 offline
Posts: 2014
Joined: Nov 26, 2009
Location: Kalispell, MT

Time Set Script Not Working

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

Posted on
Sat Apr 21, 2018 9:32 pm
ckeyes888 offline
Posts: 2014
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Time Set Script Not Working

Curious, how are people setting time variables now?
Doubt it’s by using my above script.

Thanks,

Carl

Posted on
Sun Apr 22, 2018 12:13 am
howartp offline
Posts: 3290
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Time Set Script Not Working

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

Posted on
Sun Apr 22, 2018 2:09 am
howartp offline
Posts: 3290
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Time Set Script Not Working


Posted on
Sun Apr 22, 2018 5:15 am
jalves offline
Posts: 470
Joined: Jun 16, 2013

Re: Time Set Script Not Working

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"

Running Indigo 7.1.1 on a 27" iMac (mid-2017), 8G memory, 1T Fusion Drive, OS X 10.13.6
Jeff

Posted on
Sun Apr 22, 2018 8:12 am
ckeyes888 offline
Posts: 2014
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Time Set Script Not Working

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

Posted on
Sun Apr 22, 2018 8:14 am
howartp offline
Posts: 3290
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Time Set Script Not Working

Definitely.


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Apr 22, 2018 3:27 pm
ckeyes888 offline
Posts: 2014
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Time Set Script Not Working

howartp wrote:
Definitely.

?

Carl


Sent from my iPhone using Tapatalk Pro

Posted on
Sun Apr 22, 2018 3:37 pm
howartp offline
Posts: 3290
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Time Set Script Not Working

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

Posted on
Mon Apr 23, 2018 6:08 pm
ckeyes888 offline
Posts: 2014
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Time Set Script Not Working

Might also be nice to have the am pm in lowercase.
Maybe just me but I think it looks much better.

Carl

Posted on
Mon Apr 23, 2018 8:31 pm
howartp offline
Posts: 3290
Joined: Jan 09, 2014
Location: West Yorkshire, UK

Re: Time Set Script Not Working

I agree; Python’s defaults are poor in my opinion.

Will sort.


Sent from my iPhone using Tapatalk Pro

Posted on
Tue Apr 24, 2018 10:22 am
jay (support) offline
Site Admin
User avatar
Posts: 14389
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Time Set Script Not Working

ckeyes888 wrote:
Curious, how are people setting time variables now?
Doubt it’s by using my above script.


Insert Timestamp into Variable

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Apr 24, 2018 10:25 am
jay (support) offline
Site Admin
User avatar
Posts: 14389
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Time Set Script Not Working

howartp wrote:
https://github.com/howartp84/ClockDisplay/releases/tag/1.0.0

Tadaa


Awesome README in Github! :wink:

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Posted on
Tue Apr 24, 2018 11:08 am
ckeyes888 offline
Posts: 2014
Joined: Nov 26, 2009
Location: Kalispell, MT

Re: Time Set Script Not Working

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

Posted on
Tue Apr 24, 2018 11:39 am
jay (support) offline
Site Admin
User avatar
Posts: 14389
Joined: Mar 19, 2008
Location: Austin, Texas

Re: Time Set Script Not Working

%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.

Jay (Indigo Support)
Twitter | Facebook | LinkedIn

Who is online

Users browsing this forum: No registered users and 1 guest