LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
I'm using Applescript to get selected events from Apple Calendar, building on https://macscripter.net/viewtopic.php?id=45861
When I try to parseDefaults I get execution error back when executed inside Livecode. Does anyone have any idea why?
FYI I have given Livecode full disk access in security settings.
set defaultsReply to (do shell script "defaults read com.apple.ical SelectedEvents")
set selectedEvents to parseDefaults(defaultsReply)
return selectedEvents
set defaultsReply to (do shell script "defaults read com.apple.ical SelectedEvents")
set selectedEvents to parseDefaults(defaultsReply)
return selectedEvents
on parseDefaults(resultText)
set localUIDs to {}
set {TID, text item delimiters} to {text item delimiters, quote}
set resultItems to text items of resultText
set text item delimiters to TID
repeat with i from 1 to (count resultItems)
if i mod 2 = 0 then set end of localUIDs to resultItems's item i
end repeat
return localUIDs
end parseDefaults
rodneyt wrote: Mon Oct 24, 2022 11:22 pmThanks Bn, yes does run in script editor, but not in Livecode, and it's not obvious why...
bn wrote: Sun Oct 23, 2022 12:46 amAttention, this is AppleScript, not LCS
Klaus,
Rod knows that, "Scripteditor" is the name of Apples App to run AppleScript. "ScriptDebugger" is also an app to run AppleScript with more options than Apple's Scripteditor.
set defaultsReply to (do shell script "defaults read com.apple.ical SelectedEvents")
set localUIDs to {}
set {TID, text item delimiters} to {text item delimiters, quote}
set resultItems to text items of defaultsReply
set text item delimiters to TID
repeat with i from 1 to (count resultItems)
if i mod 2 = 0 then set end of localUIDs to resultItems's item i
end repeat
return localUIDs
resolving the subroutine somehow made it work. (?)
Please note that it can take up to a couple seconds until iCal updates the database.
The AppleScript works even when the Calendar App is not open.
Awesome Bernd, that was what I was going to try next. I will give this a go now.
It is very odd that calling this subroutine throws exception but "in-lining" it is fine. I wonder if we should try to reduce it to minimum viable bug producing recipe and file as a bug report....
set defaultsReply to (do shell script "defaults read com.apple.ical SelectedEvents")
set localUIDs to {}
set {TID, text item delimiters} to {text item delimiters, quote}
set resultItems to text items of defaultsReply
set text item delimiters to TID
repeat with i from 1 to (count resultItems)
if i mod 2 = 0 then set end of localUIDs to resultItems's item i
end repeat
tell application id "com.apple.iCal" -- Calendar
set theProps to properties of event id (item 1 of localUIDs) of (last calendar whose name is "Work")
end tell
return theProps
This works in OSX Applescript Script Editor app, but not when executed in Livecode.
Odd, shouldn we get a permissions request if this is needed? So youŕe saying you went in to security permissions and granted permissions manually... interesting. OK I will give this a go tomorrow!
In Automation pane of Privacy and Security I see LiveCode 10.0.0 (dp4) listed with permissions for Daylite, Chrome,DropDMG,System Events and Calendar. I don't see Livecode 9.6.4 listed, which is what I am running. When I test in Livecode 10.0.0 (dp4) I get the same error.
I wonder if I have to reauthorse the app. Reading up on this, some interesting links:
-- this resets the automation pane completely. After doing this I launched Livecode 9.6.4 and execute the applescript. I get prompted for permission to automate Calendar (click OK). The script returns execution error. When I check in automation pane in security and privacy, it shows Livecode 10.0.0 (dp4) even though that's not the version of Livecode I had open...
I also tried building my app to a standalone and executing the applescript from there. I got prompted to automate Calendar (click OK to accept) and the script returns execution error.
Attachments
Last edited by rodneyt on Thu Oct 27, 2022 2:43 am, edited 1 time in total.