The Omni Group
These forums are now read-only. Please visit our new forums to participate in discussion. A new account will be required to post in the new forums. For more info on the switch, see this post. Thank you!

Go Back   The Omni Group Forums > OmniFocus > OmniFocus Extras
FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
Simple Applescripting Help Thread Tools Search this Thread Display Modes
I have a script called CreateCalendar that I would like to slightly modify.

I have it set up so that whenever I hit the script, the tasks with due dates are uploaded to my iCal (which syncs to gCal). This is sweet, but I would like to tweak it just a smidgen but am not sure what the variable is or if I am even doing it right.

This is the original script:

Code:
		if shouldMakeDueDate and (dueDate ≠ missing value) then
			if labelPref = "prefix" then
				set eText to "Due: " & taskName
The outcome is in iCal, an event is created Titled "Due: taskName"

I would like to specify it a little more so that it creates the title: "Due: (Project name that the task is currently in): taskName"

How do I do this?


Is there documentation for all the Applescript variables in Omnifocus?
 
Code:
--CreateCalendar
--This OmniFocus script takes the tasks in the currently displayed window and creates or refreshes
--an iCal calendar with those tasks.
--Copyright 2007 Preston Holmes
--preston@ptone.com
-- v1.0 12/20/2007

--v1.01 selected last minute bug in testing for cancel button

--set this pref to not be prompted for a calendar name 
--(default is to base calendar name on OF window with confirmation)
set calName to "School Tasks"

--set this pref to false to not be asked you choices on the following
set promptPrefs to false

set shouldMakeStartDate to false -- create a calendar event for a task start date
set shouldMakeDueDate to true -- create a calendar event for a task due date
set shouldMakeDatedTaskTodos to false -- create iCal todos for events that have start of due dates
set shouldMakeUnDatedTaskTodos to false -- create iCal todos for events that do not have start or due dates
set shouldMakeAsAllDay to false -- create calendar events as all day events

set labelPref to "prefix" --set to prefix to have events labeled "Due:[task name]" or suffix for "[task name] (Due)"


tell application "OmniFocus"
	--get calendar name if not preset
	if calName = "" then
		set winName to get name of window 1
		if winName starts with "Focusing" then
			set calName to characters 13 thru -1 of winName as string
		else if winName starts with "Perspective" then
			set calName to perspective name of window 1
		else
			set calName to "OmniFocus"
		end if
		try
			display dialog "Calendar Name:" default answer calName
			
			set calName to text returned of result
		on error
			return
		end try
	end if
	
	--get user prefs if prompt is enabled
	if promptPrefs then
		set prefChoices to {"Create Events for Start Dates", "Create Events for Due Dates", "Create ToDos for tasks that have dates", "Create ToDos for tasks that do not have dates", "Create Events as All Day Events"}
		set prefs to {a reference to shouldMakeStartDate, a reference to shouldMakeDueDate, a reference to shouldMakeDatedTaskTodos, a reference to shouldMakeUnDatedTaskTodos, a reference to shouldMakeAsAllDay}
		
		choose from list prefChoices 
			with title 
			"Preferences" with prompt 
			"Configure Calendar (cmd click for multiple)" OK button name 
			"Create Calendar" with multiple selections allowed
		
		set selectedPrefs to result
		if selectedPrefs = false then return --cancel button
		
		repeat with i from 1 to count of prefChoices
			if selectedPrefs contains item i of prefChoices then
				set contents of item i of prefs to true
			end if
		end repeat
		if not (shouldMakeStartDate or shouldMakeDueDate or shouldMakeDatedTaskTodos or shouldMakeUnDatedTaskTodos) then
			display alert "You have not chosen to create anything for this calendar, choose at least on preference that Creates an event or ToDo"
			return
		end if
	end if
	
	--gather tasks from OF
	set tasklist to value of every leaf of content of document window 1 of default document
	
	--Initialize the calendar
	tell application "iCal"
		try
			set targetCal to (the first calendar whose title is calName)
		on error errMsg number errNum
			log errMsg
			log errNum
			set targetCal to make new calendar with properties {title:calName}
		end try
		--this is a wipe and restore type operation
		delete events of targetCal
		delete todos of targetCal
	end tell
	
	--Main loop, for each task create an event and/or Todo
	repeat with aTask in tasklist
		--get task attributes
		set taskID to id of aTask
		set tURL to "omnifocus:///task/" & taskID
		set taskName to name of aTask
		set taskNote to note of aTask
		set dueDate to due date of aTask
		set startDate to start date of aTask
		
		
		if shouldMakeStartDate and (startDate ≠ missing value) then
			if labelPref = "prefix" then
				set eText to "Start: " & taskName
			else
				set eText to taskName & " (Start)"
			end if
			tell application "iCal"
				set theEvent to make event at end of events of targetCal with properties 
					{start date:startDate, end date:startDate, summary:eText, description:taskName & ": " & taskNote, allday event:shouldMakeAsAllDay, url:tURL}
			end tell
		end if
		
		
		if shouldMakeDueDate and (dueDate ≠ missing value) then
			if labelPref = "prefix" then
				set eText to "Due: " & taskName
			else
				set eText to taskName & " (Due)"
			end if
			tell application "iCal"
				set theEvent to make event at end of events of targetCal with properties 
					{start date:dueDate, end date:dueDate, summary:eText, description:taskName & ": " & taskNote, allday event:shouldMakeAsAllDay, url:tURL}
			end tell
		end if
		
		if ((startDate ≠ missing value or dueDate ≠ missing value) and shouldMakeDatedTaskTodos) then
			tell application "iCal"
				make new todo at end of todos of targetCal with properties 
					{summary:taskName, description:taskName & ": " & taskNote, due date:dueDate, url:tURL}
			end tell
		else if shouldMakeUnDatedTaskTodos then
			tell application "iCal"
				make new todo at end of todos of targetCal with properties 
					{summary:taskName, description:taskName & ": " & taskNote, url:tURL}
			end tell
		end if
	end repeat
	
	
end tell
tell application "iCal" to activate
 
Quote:
Originally Posted by anmpir View Post
Is there documentation for all the Applescript variables in Omnifocus?
You can peruse the OmniFocus dictionary. Script Editor > File > Open Dictionary > OmniFocus.
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
applescripting help for graphics on shared layers supertwang OmniGraffle General 3 2011-12-07 08:33 PM
Applescripting reference for OO3 timwilson AppleScripting Omni Apps 2 2010-07-12 07:57 AM
Applescripting Text Attachments? Charles Turner AppleScripting Omni Apps 6 2009-06-30 07:13 AM
Applescripting Import and Export -> PNG to EPS iboy OmniGraffle General 2 2008-06-25 12:55 PM
AppleScripting "My Shared Bookmarks" jerrykrinock OmniWeb General 0 2006-10-23 06:59 AM


All times are GMT -8. The time now is 11:26 PM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2019, vBulletin Solutions, Inc.