The Omni Group Forums

The Omni Group Forums (http://forums.omnigroup.com/index.php)
-   OmniFocus Extras (http://forums.omnigroup.com/forumdisplay.php?f=44)
-   -   Applescript access to attachments ? (http://forums.omnigroup.com/showthread.php?t=5100)

RobTrew 2011-03-23 09:52 AM

There is a table listing attached files in the cache.

You should be able to read it like this:

[CODE]on run
tell application "OmniFocus"
tell front document window of default document
set lstID to id of selected trees of content where class of value = task or class of value = inbox task
if length of lstID < 1 then return
set strTaskID to first item of lstID
end tell
end tell


AttachmentList(strTaskID)
end run

on AttachmentList(strTaskID)
set strCMD to "sqlite3 ~/Library/Caches/com.omnigroup.OmniFocus/OmniFocusDatabase2 'select name from Attachment where task=\"" & strTaskID & "\"'"
paragraphs of (do shell script strCMD)
end AttachmentList
[/CODE]

Kevin Yank 2011-03-23 01:22 PM

Wow, you drill into the SQLite database directly! That’s awesome, thanks!

Is this documented anywhere, perchance?

Kevin Yank 2011-03-23 01:43 PM

OK, now I’ve got a note containing File Attachments that I can save, and an sqlite table containing the filenames of the attachments, but I can’t figure out how to pair them up. Which filename goes with which File Attachment?

Any tips? It would be easy if the File Attachment object had a persistentIdentifier property or something that showed up in the sqlite table.

RobTrew 2011-03-23 02:18 PM

[I]name[/I] is only one of the fields in the table.
[INDENT]persistentIdentifier text,
containingTransactionHint text,
context text,
creationOrdinal integer,
dateAdded timestamp NOT NULL,
dateModified timestamp NOT NULL,
folder text,
name text,
perspective text,
previewPNGData blob,
task text[/INDENT]
The OmniFocus.ofocus package contains various zip files.
The name of the zip file containing the attachment is given by the field [I]containingTransactionHint[/I].

If the relevant file is unzipped, you will find that it contains a folder named [I]data[/I], containing subfolders with unique names. The [I]persistentIdentifier[/I] fields gives the name of the subfolder containing the file specified in the record.

[COLOR="White"]--[/COLOR]

Kevin Yank 2011-03-23 03:40 PM

[QUOTE=RobTrew;95104][I]name[/I] is only one of the fields in the table…[/QUOTE]

Thanks for the added detail! I’m still stumped on how to match up the File Attachments visible to my AppleScript to the file names present in the Attachments table, however.

The Support Ninjas tell me that[code]get file name of aFileAttachment[/code] should work. I’ve reported the fact that it doesn’t work with embedded attachments as a bug.

RobTrew 2011-03-23 04:00 PM

[QUOTE=Kevin Yank;95107]I’m still stumped on how to match up the File Attachments visible to my AppleScript to the file names present in the Attachments table[/QUOTE]

Do you need to ? I would have thought that all you need from the applescript is the id of the task/project.

From there the information in the cache will take you straight to the files ...

Kevin Yank 2011-03-23 05:38 PM

Ah, I see what you mean! Ignore the AppleScript File Attachment objects entirely and rely on the sqlite database to enumerate and locate the file attachments.

I could see that working, but I’m trying to write an AppleScript that I can invoke to send the selected task(s) (and their attachments) to another application. Unzipping the transaction file for each task to access the attachments seems like it would be a slow and inefficient process for what I’m trying to achieve.

I’ll wait and see what the Ninjas say about the apparent bug in their AppleScript support for attachments. Failing that, I’ll take another look at drilling into that database.

Thanks again!


All times are GMT -8. The time now is 02:04 AM.

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