Attach File Link

In OF for macOS, there is the possibility to add the link to a file on the hard drive to a note. This is very convenient to quickly access a file and is also described in a recent OmniShow).

The method is described here in the OF help. A very similar methodology is implemented in OmniOutliner.

** → is it possible to generate such a link in applescript (or in some other way) automatically?**

I am asking because I try to setup a Hazel rule that creates a new OF task when a new file occurs in a folder, and this would provide easy access to this file?

In the distant past, I have been doing this with

tell application "System Events" to set myFileUrl to URL of theFile

However, the resulting link that starts with file:///... seems to not work from any mac app anymore… Is this a generally true or is something wrong with my setup?

** UPDATE 2020-Dec-05 **

ok, I have this script that watches the folder and creates a task in the proper project with the proper tag

set theDate to current date
set theTask to “Rechnung ABC”

set theNote to “Scanned and processed on” & (theDate as string) & return

tell application “OmniFocus”
 tell front document
  set theTag to first flattened tag where its name = “do online”
  set theProject to first flattened project where its name = “Finanzen”
  set theDueDate to theDate + (24 * hours)
  tell theProject to make new task with properties {name:theTask, note:theNote, primary tag:theTag, due date:theDueDate}
 end tell
end tell

on the other hand, I have this code, that likely mimics the “generate link” feature that I mention at the beginning:

tell application “OmniFocus”
 tell quick entry
  open
  set NewTask to make new inbox task with properties {name:file_name}
  tell the note of NewTask
   make new file attachment with properties {file name:this_item, embedded:true}
  end tell
  activate
 end tell
end tell

So, in the first example, how do I tell the note (note:theNote) that I create within the new task of theProject to include the file attachment? – I would prefer the note created in the proper project and not in the quick entry.

Thanks for your help.
Claus

ok, this works now for me:

tell application “OmniFocus”
 tell front document
  set theTag to first flattened tag where its name = “do online”
  set theProject to first flattened project where its name = “Finanzen”
  set theDueDate to theDate + (24 * hours)
  tell theProject
   set theOtherTask to make new task with properties {name:theTask, note:theNote, primary tag:theTag, due date:theDueDate}
   tell the note of theOtherTask
    make new file attachment with properties {file name:theFile, embedded:false}
    end tell
   end tell
  end tell
end tell

credits

However, this aspect of the question remains: what kind of link is this? – When I copy and past to TextEdit it resolves to the previously mentioned file:///... – and does not work from within TextEdit. Which is… annoying… – Why does it work from within OmniFocus and what could be done such it would work from elsewhere?

< well, this question would apply to both the general OF part and the applescript part of this forum… not sure if cross-posting would have been a good idea />

Thanks,
Claus

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.