Hello,
I need to send string variables (time in the format 00:00) from a variable collected with AppleScript to a Keyboard Maestro variable. I keep getting:
"Can’t make characters 1 thru 5 of text document id 220 of application "BBEdit" into the expected type."
Using Script Debugger, I see that the variable StartTime has three found properties:
found: true
found object: characters 1 thru 5 of text document id 220
found text: "08:30"
I want to send the value 08:30 from the AppleScript variable StartTime to Keyboard Maestro Variable TicketTimeEntryBegin
The current script is as follows, the offending line being the last part: set "TicketTimeEntryBegin" to StartTime
set StartTime to "00:00"
set EndTime to "00:00"
set ClientCode to "AAA"
tell application "BBEdit"
set StartTime to find "(\\A)([0-9]{2})(\\:)([0-9]{2})" searching in text document 1 options {search mode:grep, wrap around:true} with selecting match
set EndTime to find "([0-9]{2})(\\:)([0-9]{2})" searching in text document 1 options {search mode:grep, wrap around:false} with selecting match
set ClientCode to find "[A-Z]{3}" searching in text document 1 options {search mode:grep, wrap around:false} with selecting match
end tell
tell application "Keyboard Maestro Engine"
set value of variable "TicketTimeEntryBegin" to StartTime
end tell
Thanks!
When I tried this:
First I got an undefined variable, and had to define the variable from Keyboard Maestro in the AppleScript
Second, I got the same message:
Can’t make characters 1 thru 5 of text document id 220 of application "BBEdit" into the expected type.
Offending object: characters 1 thru 5 of text document id 220
As stated in the original post, I'm seeing these three properties for the AppleScript variable StartTime:
found: true
found object: characters 1 thru 5 of text document id 220
found text: "08:30"
Is it not passing the "found text" 08:30 to KM, and instead trying to pass "characters 1 thru 5 of text document id 220"?
Oh, by the way, I'm writing the script in Script Debugger, not in a Keyboard Maestro AppleScript step - is that my problem?
Here's the current state of the AppleScript:
set StartTime to "00:00"
set TicketTimeEntryBegin to "00:00"
set EndTime to "00:00"
set ClientCode to "AAA"
tell application "BBEdit"
set StartTime to find "(\\A)([0-9]{2})(\\:)([0-9]{2})" searching in text document 1 options {search mode:grep, wrap around:true} with selecting match
set EndTime to find "([0-9]{2})(\\:)([0-9]{2})" searching in text document 1 options {search mode:grep, wrap around:false} with selecting match
set ClientCode to find "[A-Z]{3}" searching in text document 1 options {search mode:grep, wrap around:false} with selecting match
end tell
tell application "Keyboard Maestro Engine"
getvariable TicketTimeEntryBegin
setvariable TicketTimeEntryBegin to StartTime
end tell
I don’t have an answer for your “real” problem as I’m away from my Mac, but you’re still using the AppleScript interface to KM variables incorrectly: the model I gave you covered both getting a value from KM and also passing a value back to KM.
So in your case to set the value of a KM variable you should use something like this:
tell application "Keyboard Maestro Engine"
setvariable <nameOfKMVariable> to <nameOfAppleScriptVariable>
end tell
The “getvariable” word is for when you want to pass the value of a KM variable into an AppleScript variable - something like:
tell application "Keyboard Maestro Engine"
set <nameOfAppleScriptVariable> to getvariable <nameOfKMVariable>
end tell
Well here's another clue. When I build a small test script using and Execute Script action in KM thus:
tell application "BBEdit"
find "(\\A)([0-9]{2})(\\:)([0-9]{2})" searching in text document 1 options {search mode:grep, wrap around:true} with selecting match
end tell
And the script uses "Save to Variable" to variable "TicketTimeEntryBegin"
What I get in Keyboard Maestro for TicketTimeEntryBegin is:
found:true, found object:characters 1 thru 5 of text document id 220, found text:08:30
So I'm getting this set of three properties for the Find command in BBEdit, not just the text value itself.
I think I might be using the find command for BBEdit incorrectly. Honestly I don't know what "with selecting match" does in the AppleScript find line, only that I copied it from another script, and it doesn't return ANYTHING without it