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

 
Adjusting of AppleScript to add project, context and start date Thread Tools Search this Thread Display Modes
Hi Dale,

thanks for that help. After putting all scripts ones after ones your's worked well - I found that i did a copy error and missed the first line.

BTW: I've edited your script a little bit to add the date of the scan (stole that at asianeffiecncy):

Code:
tell application "Finder" to set file_name to (name of theFile)
set theDate to current date
set theNote to "Scanned " & (theDate as string) & " 

"

tell application "OmniFocus"
	set task_title to "Proceed: " & file_name
	tell default document
		set theContext to first flattened context where its name = "Review"
		set newTask to make new inbox task with properties {name:task_title, context:theContext}
		set note of newTask to theNote
		tell the note of newTask
			make new file attachment with properties {file name:theFile, embedded:false}
		end tell
	end tell
end tell
Thanks a lot man! To get it into the right project is quite easier as you can drag and drop a lot of tasks to a project :-)
 
It is good to hear you have something working and is useful for you. The point of my bringing up all the scripts/references was to help give background to the original script you posted and at least get that working for you.

I would strongly suggest to take a look at the script Rob Trew presented as a solution in this thread when you have time. His scripts are very well done and I use many of them in my personal workflows. Besides his script is much more sophisticated and offers more features than my simple cobbling together of these other scripts.
 
Yeah, i'll have a look at Rob's script, maybe I'll be able to get it working :)
 
Quote:
Originally Posted by RobTrew View Post
It seems that Applescript code embedded in Hazel can't use function definitions (Hazel probably wraps the code in a function handler).

You should be able to unpackage the functions along these lines:

Code:
tell application "Finder" to set file_name to (name of theFile)

set theDate to current date
set theNote to "Scanned " & (theDate as string) & " 

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
	set task_title to theTask
	tell default document
		-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT 
		set lstProj to flattened projects where name = projectname
		if lstProj ≠ {} then
			set oProj to item 1 of lstProj
		else
			set oProj to (make new project with properties {name:projectname})
		end if
		
		-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
		set lstContexts to flattened contexts where name = ContextName
		if lstContexts ≠ {} then
			set oContext to item 1 of lstContexts
		else
			set oContext to (make new context with properties {name:ContextName})
		end if
		
		-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT, ATTACHING IT TO THE SPECIFIED CONTEXT
		tell oProj
			tell (make new task with properties {name:task_title, context:oContext})
				set its note to theNote
				tell its note to make new file attachment with properties {file name:file_name, embedded:false}
			end tell
		end tell
	end tell
end tell
I have to admit that I'm really stupid. This script works like a charm if you copy it right. I forgot the first line again... Sorry for beeing so dumb!

Just one more question: Can you help me to add a Start Date for that task as well? I'd like something like "today+3".

Cheers,
Ben

PS: Rob you are truly a hero!
 
Quote:
Originally Posted by hubutz View Post
I forgot the first line again...
No problem – easily done.

Quote:
a Start Date for that task as well? I'd like something like "today+3"
Perhaps something along these lines:

Code:
tell application "Finder" to set file_name to (name of theFile)

set dteBase to current date
set theNote to "Scanned " & (dteBase as string) & " 

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
	set task_title to theTask
	tell default document
		-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT 
		set lstProj to flattened projects where name = projectname
		if lstProj ≠ {} then
			set oProj to item 1 of lstProj
		else
			set oProj to (make new project with properties {name:projectname})
		end if
		
		-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
		set lstContexts to flattened contexts where name = ContextName
		if lstContexts ≠ {} then
			set oContext to item 1 of lstContexts
		else
			set oContext to (make new context with properties {name:ContextName})
		end if
		
		-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT, 
		-- ATTACHING IT TO THE SPECIFIED CONTEXT
		-- AND STAMPING IT WITH A START DATE
		
		set dteStart to dteBase - (time of dteBase) -- zero the time to midnight
		set dteStart to dteStart + (3 * days) -- and add three days
		
		tell oProj
			tell (make new task with properties {name:task_title, context:oContext, start date:dteStart})
				set its note to theNote
				tell its note to make new file attachment with properties {file name:file_name, embedded:false}
			end tell
		end tell
	end tell
end tell
 
Quote:
Originally Posted by hubutz View Post
Just one more question: Can you help me to add a Start Date for that task as well? I'd like something like "today+3".
This works for me.

Code:
tell application "Finder" to set file_name to (name of theFile)

set theDate to current date

set theStartDate to current date
set time of theStartDate to 0 + (8 * hours)

set theNote to "Scanned " & (theDate as string) & " 

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
	set task_title to theTask
	tell default document
		-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT 
		set lstProj to flattened projects where name = projectname
		if lstProj ≠ {} then
			set oProj to item 1 of lstProj
		else
			set oProj to (make new project with properties {name:projectname})
		end if
		
		-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
		set lstContexts to flattened contexts where name = ContextName
		if lstContexts ≠ {} then
			set oContext to item 1 of lstContexts
		else
			set oContext to (make new context with properties {name:ContextName})
		end if
		
		-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT, ATTACHING IT TO THE SPECIFIED CONTEXT
		tell oProj
			tell (make new task with properties {name:task_title, context:oContext, start date:(theStartDate) + (3 * days)})
				set its note to theNote
				tell its note to make new file attachment with properties {file name:file_name, embedded:false}
			end tell
		end tell
	end tell
end tell
To modify the time change the number of hours using 24hour time in the this line of code.

Code:
set time of theStartDate to 0 + (8 * hours)
 
Quote:
Originally Posted by RobTrew View Post
No problem – easily done.



Perhaps something along these lines:

Code:
tell application "Finder" to set file_name to (name of theFile)

set dteBase to current date
set theNote to "Scanned " & (dteBase as string) & " 

"
set projectname to "Proceed Files"

set ContextName to "Some Context"

set theTask to "Proceed: \"" & file_name & "\""

tell application "OmniFocus"
	set task_title to theTask
	tell default document
		-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT 
		set lstProj to flattened projects where name = projectname
		if lstProj ≠ {} then
			set oProj to item 1 of lstProj
		else
			set oProj to (make new project with properties {name:projectname})
		end if
		
		-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
		set lstContexts to flattened contexts where name = ContextName
		if lstContexts ≠ {} then
			set oContext to item 1 of lstContexts
		else
			set oContext to (make new context with properties {name:ContextName})
		end if
		
		-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT, 
		-- ATTACHING IT TO THE SPECIFIED CONTEXT
		-- AND STAMPING IT WITH A START DATE
		
		set dteStart to dteBase - (time of dteBase) -- zero the time to midnight
		set dteStart to dteStart + (3 * days) -- and add three days
		
		tell oProj
			tell (make new task with properties {name:task_title, context:oContext, start date:dteStart})
				set its note to theNote
				tell its note to make new file attachment with properties {file name:file_name, embedded:false}
			end tell
		end tell
	end tell
end tell
Thanks a lot Rob! This works perfectly and will give me some more spare time :-)

@Dale: thanks for your help as well!
But I don't get this. Why do i want to add 8 * hours? Do i have to add 72 instead of hours if i want 3 days? :)

Quote:
Originally Posted by Dale View Post
To modify the time change the number of hours using 24hour time in the this line of code.

Code:
set time of theStartDate to 0 + (8 * hours)
 
Quote:
Originally Posted by hubutz View Post
@Dale: thanks for your help as well!
But I don't get this. Why do i want to add 8 * hours? Do i have to add 72 instead of hours if i want 3 days? :)
I had posted my script modification before I saw Rob Trew also had posted a response. My script has two parts to it; start date of 3 days from the current date, and start time of 8AM.

Part one:

Set the start date to equal the current date.

Code:
set theStartDate to current date
Added the start date property to the task to start in three days.

Code:
start date:(theStartDate) + (3 * days)
Part two:

Added the option for setting a start time to the start date being added to the task. By default the start time is the time the script is run. I wanted to set the tasks to start at a specific time.

Code:
set time of theStartDate to 0 + (8 * hours)
The line above controls the time you want the tasks to start. The "8" means 8AM. If you wanted the tasks to begin at 8PM you would use "20". I like to use start times with my tasks and I could have explained this a lot better.
 
Ahh, thanks - that makes sense. I think I'll have a deeper look into programming or scripting if the summer keeps sucking that much... seems to be pretty helpful and straight forward!
 
Hello everyone,
Thank you RobTrew for this great script!
I just have a question about file attachment : when I set embedded:true, I get a repetition of the introduction of the task in Omnifocus indefinitely and without the file is attached.

Thank you to enlighten me.
Wonderfull Forum !!!

here is the script I've used and the image of the result :
Code:
tell application "Finder" to set file_name to (name of theFile)

set dteBase to current date
set theNote to "Scanned " & (dteBase as string) & " 

"
set projectname to "Factures à Encoder"

set ContextName to "En-Ligne"

set theTask to "Encoder: \"" & file_name & "\""

tell application "OmniFocus"
	set task_title to theTask
	tell default document
		-- GET A REFERENCE TO AN EXISTING PROJECT (OR NEW) PROJECT 
		set lstProj to flattened projects where name = projectname
		if lstProj ≠ {} then
			set oProj to item 1 of lstProj
		else
			set oProj to (make new project with properties {name:projectname})
		end if
		
		-- GET A REFERENCE TO AN EXISTING (OR NEW) CONTEXT
		set lstContexts to flattened contexts where name = ContextName
		if lstContexts ≠ {} then
			set oContext to item 1 of lstContexts
		else
			set oContext to (make new context with properties {name:ContextName})
		end if
		
		-- MAKE A NEW TASK UNDER THE SPECIFIED PROJECT, 
		-- ATTACHING IT TO THE SPECIFIED CONTEXT
		-- AND STAMPING IT WITH A START DATE
		
		set dteStart to dteBase - (time of dteBase) -- zero the time to midnight
		set dteStart to dteStart + (10 * days) -- and add three days
		
		tell oProj
			tell (make new task with properties {name:task_title, context:oContext, start date:dteStart, flagged:true})
				set its note to theNote
				tell its note to make new file attachment with properties {file name:file_name, embedded:true}
			end tell
		end tell
	end tell
end tell
Attached Thumbnails
Click image for larger version

Name:	HazelOF.png
Views:	862
Size:	37.1 KB
ID:	2882  
 
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes



All times are GMT -8. The time now is 12:05 PM.


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