Wednesday, January 19, 2022

#1 2022-01-15 02:01:58 am

peetysmith
Member
Registered: 2022-01-13
Posts: 1

Challenge Accessing Item Properties

Hi All,

I'm trying to do something to spot free/available time across multiple calendars.

First step is to get all of the calendar information. I'm able to successfully do that...

Applescript:


set theCal to calendar id 116
set theDate to current date

set entries to every calendar event of theCal whose start time is greater than or equal to theDate

This gets me all of the calendar entries for calendar id 116.

When I try to access the items in "entries" though it behaves strangely and I only seem to be able to access the properties properly when I return the value rather than through a dialogue or logging.

This code...

Applescript:


repeat with entry in entries
log entry's subject
return entry's subject
end repeat

Gives the following output...
subject of calendar event id 3429
Cancel Zacks ultimate membership

Whatever I seem to use (id, subject start time, etc) the return statement works correctly and the log just prints out the name of the property prefix to "of calendar event id 3429", eg "id of calendar event id 3429".

I'm a newbie to AppleScript so I'm not sure if this is an issue or I'm just doing it entirely incorrectly!

Thanks,
Pete

Offline

 

#2 2022-01-15 06:03:31 am

Nigel Garvey
Moderator
From:: Warwickshire, England
Registered: 2002-11-20
Posts: 5473

Re: Challenge Accessing Item Properties

Hi. Welcome to MacScripter.

Ideally, you should say what application you're trying to script. The 'id's of macOS's own Calendar app aren't in that format and it doesn't have 'calendar events', 'start times', or 'subjects'.

But I think the problem you're describing is a quirk of the 'log' command. It's not important to the working of the script. But a workaround might be force the resolution of the 'subject of calendar event' specifier by setting a variable with it and logging the result of that:

Applescript:

repeat with entry in entries
   set theSubject to entry's subject -- Set a variable to the subject of the calendar event.
   log theSubject
   return theSubject -- Presumably this is for test purposes
end repeat


NG

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)