These steps work well for me and I’m grateful to all of you for the tutorial.
I would mention that this script requires an “Inbox” note or container in the target TBX file in order to work properly; not sure anyone mentioned that.
These steps work well for me and I’m grateful to all of you for the tutorial.
I would mention that this script requires an “Inbox” note or container in the target TBX file in order to work properly; not sure anyone mentioned that.
I modified the script according to my personal needs. I wanted to get the title of the Drafts note to become the $Name attribute of the TBX note - without having to select any text. And I wanted the title to be removed from the content in the $Text attribute. Ah - and a link to the note will be added as $ReferenceURL.
-- The action must be initiated from a note in Drafts.app while the title of the note will become the $Name of the TBX note.
-- the script is based on the work of midas0441 (TBX forum)
on execute(draft)
set theTBXFile to "/Users/detlefbeyer/Desktop/test.tbx"
set theTitle to title of the draft
set theFullBody to the content of the draft
set theCleanBody to returnContentWithoutFirstLine(theFullBody)
set theCreateDate to ("" & createdAt of the draft)
set theModifyDate to ("" & modifiedAt of the draft)
set theTags to (tags of the draft)
set theListOfTags to convertListToString(theTags, "; ")
set theLinkToDrafts to the permalink of the draft
tell application id "Cere"
open theTBXFile
tell front document
set theContainer to note "inbox"
set myNote to make new note with properties {name:theTitle} at theContainer
tell myNote
set value of attribute "Text" to theCleanBody
set value of attribute "Created" to theCreateDate
set value of attribute "Modified" to theModifyDate
set value of attribute "Tags" to theListOfTags
set value of attribute "ReferenceURL" to theLinkToDrafts
set value of attribute "Prototype" to "Markdown"
set value of attribute "DisplayedAttributes" to "Created;Modified;Tags;ReferenceURL"
end tell
end tell
end tell
end execute
on convertListToString(theList, theDelimiter)
set AppleScript's text item delimiters to theDelimiter
set theString to theList as string
set AppleScript's text item delimiters to ""
return theString
end convertListToString
on returnContentWithoutFirstLine(allContent)
set theResult to ""
set theFirstNonEmptyLine to returnTheFirstNonEmptyLine(allContent)
set text item delimiters to return
set theResult to (paragraphs theFirstNonEmptyLine thru -1) of allContent as string
set text item delimiters to ""
return theResult
end returnContentWithoutFirstLine
on returnTheFirstNonEmptyLine(allContent)
set theResult to 2
repeat with i from 2 to the number of paragraphs in allContent
if paragraph i of allContent is not "" then
set theResult to i
exit repeat
end if
end repeat
return theResult
end returnTheFirstNonEmptyLine
Next thing is that I would like to have the note in Drafts moved to the archive. I found no method in AppleScript so I added a 2nd step using JavaScript:
// Drafts - Archive
// move draft into the Archive
draft.isArchived = true;
draft.update();
That’s it.
Many thanks Detlef for the excellent script above.
One slight debug error I found is:
‘set value of attribute “Prototyp” to “Markdown”’
Prototype is misspelled: Prototyp → Prototype
and for those new to applescript, you will need to modify your own location here:
set theTBXFile to “/Users/detlefbeyer/Desktop/test.tbx”
Many thanks Detlef
Tom
[Admin note: As admin access allows me to make edits after the grace period, I’ve amended the typo above to assist others with copy/pate of the code. ]
Hi Tom - this was the only line I didn’t copy but wrote directly here into the forum
I’m still thinking if I should set the TBX prototype via Script in Draft or add an Edict to the Tinderbox “inbox” container - both option will do it…
Or, you could set the $Prototype in the OnAdd action of the inbox container.
As admin access allows me to make me make edits after the grace period, I’ve amended the typo above to assist others with copy/paste of the code.
One other, minor correction in the line:
set value of attribute “KeyAttributes” to “Created;Modified;Tags;ReferenceURL”
Tinderbox renamed KeyAttributes → “DisplayedAttributes”
I would recommend also updating the code to reflect the change.
Thanks
Tom
Good point. Will amend.
Done, in both code examples up-thread.
To explain, DisplayedAttributes replaced KeyAttributes (and associated attributes in v8 [sic]. A new doc continues to contain the old attributes and for legacy support only the Displayed Attributes and Key Attributes values map to each other.
But, in v9 we shouldn’t be using new code that only works for legacy compatibility reasons. IOW, it may need updating in due course when using Displayed Attributes will keep working.
Ok, I promise this is the last comment code I found.
This line works as is if I used a tinderbox file that was place in the $Path location like the “Desktop”. Mine was not located there. Interestingly, it failed for my files stored in iCloud. See below
‘set theTBXFile to “/Users/YourUserNameHere/Desktop/test.tbx”’
Here is what I changed to make it work for my tinderbox file in icloud NB the “/” at the beginning was changed to “//”
“//Users/YourUserNameHere/Library/Mobile Documents/com~apple~CloudDocs/TinderboxICloudDrive/_Tbxs/_ActiveTbxs/m/_me.tbx”
I do not understand the difference in using $Path names with Applescript syntax but perhaps MarkA or someone else can explain the logic. I think it has to do with the space in the “Mobile Documents” name but I am unsure.
I posted this to help others. My script is working great now with the above changes.
Cheers,
Tom
Hi Tom,
“//” or “/” should make no difference on the Mac as far as I can tell.
However the iCloud Drive doesn’t act like a normal Finder folder. The path to the iCloud drive should be “~/Library/Mobile\ Documents/com~apple~CloudDocs/” - while the tilde is a shortcut for the current users home directory (if you like to address a specific user instead of the current user: replace the tilde with /Home/USERNAME as you did).
So “~/Library/Mobile\ Documents/com~apple~CloudDocs/TinderboxICloudDrive/_Tbxs/_ActiveTbxs/m/_me.tbx” should do it too.
Detlef
Sorry, not my area of expertise. however, on reading, I note the following…
Um, I think a double //
snuck in the middle there, after ‘CloudDocs’. Shouldn’t the path be
"~/Library/Mobile\ Documents/com~apple~CloudDocs/_Tbxs/_ActiveTbxs/m/_me.tbx"
But looking at @TomD’s example the path is actionally
"~/Library/Mobile\ Documents/com~apple~CloudDocs/TinderboxICloudDrive/_Tbxs/_ActiveTbxs/m/_me.tbx"
…otherwise we lose the ‘TinderboxICloudDrive’ folder.
It’s confusing that the tilde ~
gets used two different ways. The one at the start is a Unix-style ‘shortcut’ for the user’s home directory. For use with short user account name ‘xyz’, expaning the first tilde gives:
"/Users/xyz/Library/Mobile\ Documents/com~apple~CloudDocs/TinderboxICloudDrive/_Tbxs/_ActiveTbxs/m/_me.tbx"
The second use of the tilde is a a a literal character in the folder named ‘com~apple~CloudDocs’. So, not really confusing at all.
Thank you @webline for this very helpful script.
Is there a way of batch-sending a couple of Drafts-Notes to Tinderbox simultaneously?
Hi Andreas,
this should be possible - you need a loop to collect all items in Drafts and a loop in TBX to create individual notes. If I find the time I’m happy to create an update of my script - or try it yourself - not to complicated…
Best,
Detlef