passing filename of finderselection to Omnifocus item-title

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

…this is what I’m already doing (and I’m verrry close to putting the finishing touch)
1. select a file in the Finder
2. add a comment to it like: #learn, #organize, etc…
3. this triggers in several actions being taken successfully & to finish them off I create an inbox-item in OmniFocus to remember me I have to do something with that file

It’s the last part that I’m using the following script for. What does this script successfully do?
    part1: parse the name of the selected file in the Finder, WITHOUT an extension. It returns the file name without extension successfully
    part2: create an Omnifocus-item in the right context/project etc… In this part, the title is being defined
What it still has to do:
- the title of the note has been configured to start with “Have a look at ….” -> but behind this I want to add the name of the file I have selected in the beginning of the flow. Whatever I do it doesn’t work, so any help appreciated.

the script:
Code: Select all
--part 1: getting the finder's item name without an extension
tell application "Finder" to set theSelection to selection
repeat with anItem in theSelection
   set theLocation to POSIX path of (anItem as text)
   set {name:fileName, name extension:nameExtension} to anItem
   set baseName to text 1 thru ((get offset of "." & nameExtension in fileName) - 1) of fileName
end repeat
--part 2: creating the Omnifocus item
set theDate to current date
set DeferredDate to ((current date) + 3600 * 24 * 5)
set theTask to "Have a look at..." & (fileName as string)
set theNote to "File added to rMBP-OneDrive > Learn on " & (theDate as string)

tell application "OmniFocus"
   tell front document
      set theContext to first flattened context where its name = "Full Focus"
      set theProject to first flattened project where its name = "Refine Analysis Skills"
      tell theProject to make new task with properties {name:theTask, note:theNote, context:theContext, defer date:DeferredDate}
   end tell
end tell

Stingo
 
Posts: 8
Joined: Sat Feb 28, 2015 10:52 am

This seems to be more of a general scripting or Omnifocus scripting question. Also, not sure how this even connects to Hazel since you don't take in a file argument. If you take in the file from Finder, it seems that this script is totally disconnected from Hazel.
Mr_Noodle
Site Admin
 
Posts: 11867
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support