• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Speeding up OmniFocus/Calendar Script
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Speeding up OmniFocus/Calendar Script


  • Subject: Speeding up OmniFocus/Calendar Script
  • From: Christian F <email@hidden>
  • Date: Tue, 25 Apr 2017 22:31:10 -0400

Hello,

I'm relatively new to AppleScript and have just finished my first useful script. I've always wanted to repeat OmniFocus tasks based on calendar events and have written this script to hold me over until that functionality is added to OmniFocus. Is there a way to speed up this script? It takes ~10 seconds right now. Can I do anything to improve it?

Note: It requires the CalendarLib EC library.

Thank you!

Christian

-------------------------------------------------------------------------------------------

use script "CalendarLib EC" -- https://www.macosxautomation.com/applescript/apps/Script_Libs.html#CalendarLib_EC
use scripting additions

set d1 to current date
set day of d1 to 1
set d2 to current date
set day of d2 to daysInMonth(d1)
set createdCount to 0

set theStore to fetch store
set theCal to fetch calendar "Work" cal type cal cloud event store theStore -- change calendar here
set theEvents to fetch events starting date d1 ending date d2 searching cals theCal event store theStore

repeat with anEvent in theEvents
set eventInfo to event info for event anEvent
set eventStart to eventInfo's event_start_date
set eventEnd to eventInfo's event_end_date
tell application "OmniFocus"
tell front document
set theTask to "List some items on eBay" -- change task title here
set theProject to (first flattened project where its name = "Work Actions") -- change project here
set theContext to (first flattened context where its name = "Work") -- change context here
if not (exists (first flattened task where its name = theTask and its context = theContext and its defer date = eventStart and its due date = eventEnd - (hours * 2))) then
tell theProject to make new task with properties {name:theTask, context:theContext, defer date:eventStart, due date:eventEnd - (hours * 2)}
set createdCount to createdCount + 1
end if
end tell
end tell
end repeat

if createdCount = 1 then
set tasks to "task"
else if createdCount ≠ 1 then
set tasks to "tasks"
end if

display dialog "Created " & createdCount & " new \"" & theTask & "\" " & tasks & "." buttons {"OK"} default button "OK"

-------------------------------------------------------------------------------------------
# HANDLERS
-------------------------------------------------------------------------------------------
on daysInMonth(aDate)
--http://stackoverflow.com/questions/39055945
local aDateCopy
copy aDate to aDateCopy
set day of aDateCopy to 1
if month of aDateCopy is December then
set year of aDateCopy to ((year of aDateCopy) + 1)
set month of aDateCopy to 1
else
set month of aDateCopy to ((month of aDateCopy) + 1)
end if
return day of (aDateCopy - 1 * days)
end daysInMonth
-------------------------------------------------------------------------------------------


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: Another 'Mail' hassle
  • Next by Date: re: Another 'Mail' hassle
  • Previous by thread: re: Another 'Mail' hassle
  • Next by thread: Help Please! Applescript Editor goes into tight loop
  • Index(es):
    • Date
    • Thread