I’m making an action to shorten URLs via TinyURL. I intend to use the action on Mac + iOS.
I’m mostly going to use this to shorten x-callback-urls so I can use them in Notion, but it’ll be useful in general I think.
I have this script, which works when I test it in the Mac Script Editor, and fails when I run it in Drafts.
Example script, works in Script Editor:
set draft to "bear://x-callback-url/open-note?id=DDF59ACC-6C42-42C6-B651-41D8B8B457CA-91312-0004D85C42EE3F2D&show_window=yes&new_window=yes"
set longUrl to draft
set shellScript to "curl https://tinyurl.com/api-create.php?url='" & longUrl & "'"
set shortenedUrl to do shell script shellScript
set the clipboard to shortenedUrl
Here is the same script, moved over to a Drafts AppleScript action:
-- AppleScript content
-- Editing and testing in Script Editor recommended
on execute(draft)
set shellScript to "curl https://tinyurl.com/api-create.php?url='" & draft & "'"
set shortenedUrl to do shell script shellScript
set the clipboard to shortenedUrl
end execute
When I test the script in Script Editor, all good. When I try in Drafts, it fails with this error:
The operation couldn’t be completed. /Users/andrew/Library/Application Scripts/com.agiletortoise.Drafts-OSX/Temp/applescript-667161091.692247.scpt: execution error: Can’t make {permalink:"drafts://open?uuid=EA4D0705-01DA-486D-BDC5-B1E5201A76E7", folderName:"inbox", createdAt:date "Monday, February 21, 2022 at 9:53:53 AM", modifiedLongitude:-118.353204953042, accessedAt:date "Monday, February 21, 2022 at 10:20:07 AM", languageGrammar:"Markdown", modifiedLatitude:34.078812588259, content:"bear://x-callback-url/open-note?id=DDF59ACC-6C42-42C6-B651-41D8B8B457CA-91312-0004D85C42EE3F2D&show_window=yes&new_window=yes", modifiedAt:date "Monday, February 21, 2022 at 10:31:30 AM", createdLongitude:-118.353209668168, createdLatitude:34.078812275776, uuid:"EA4D0705-01DA-486D-BDC5-B1E5201A76E7", flagged:false, tags:{}, title:"bear://x-callback-url/open-note?id=DDF59ACC-6C42-42C6-B651-41D8B8B457CA-91312-0004D85C42EE3F2D&show_window=yes&new_window=yes"} into type Unicode text. (-1700)