Selection to Mastodon Action

Updated 03012023-161416


Social


Selection to Mastodon Action - macOS Action Editor

Description

Post selected text to Mastodon and return the resulting status' URL as a markdown-formatted hyperlink.

Directory Description

Post selected text to Mastodon (if no text is selected, the entire draft contents will be passed) and return the resulting status' URL as a markdown-formatted hyperlink.

This is a modified version of the Post to Mastodon (Script) Action shared by agiletortoise.

As such, this advisory applies:

IMPORTANT: Before using this action, edit the first to “Define Template Tag” steps to enter the Mastodon instance host and credential identifier to use.

The differences/additions are as follows:

  1. If any text is selected at run, only the selection will be passed as the status content. For my own uses, this is/has long been a must, as I use an assigned keyboard shortcut to call this (and other social posting) action(s.)
  2. By default, the URL to the resulting status (Ex:https://mastodon.social/@DavidBlue/109950043272210317) is inserted in Markdown format after a line break, following a hyphen and a space (to form an unordered list item.) The text of the hyperlink is Mastodon out of the box, but this can easily be modified by editing the final Define Template Tag action step.
  3. Said status URL is also copied to the system clipboard.
[selected text]
- [Mastodon](https://mastodon.social/@DavidBlue/109950215153070513)

JS


Install

drafts://action?data=%7B%22notificationType%22:2,%22disposition%22:0,%22assignTags%22:%5B%5D,%22icon%22:%22action_mastodon%22,%22groupDisposition%22:0,%22uuid%22:%2252689DA9-1EE0-4F8B-BF07-20B07AC1D1F1%22,%22visibility%22:480,%22name%22:%22Selection%20to%20Mastodon%22,%22groupUUID%22:%22896E9936-31AB-4722-A67D-AA578EABE763%22,%22tintColor%22:%22violet%22,%22backingPlatforms%22:3,%22keyCommand%22:%7B%22optionKey%22:true,%22input%22:%22M%22,%22controlKey%22:true,%22commandKey%22:false,%22type%22:%22action%22,%22discoverabilityTitle%22:%22Selection%20to%20Mastodon%22,%22shiftKey%22:true%7D,%22keyUseIcon%22:false,%22backingIsSeparator%22:false,%22shortName%22:%22%22,%22backingActionType%22:%22action%22,%22actionDescription%22:%22Post%20selected%20text%20to%20Mastodon%20and%20return%20the%20resulting%20status'%20URL%20as%20a%20markdown-formatted%20hyperlink.%22,%22logLevel%22:2,%22steps%22:%5B%7B%22platforms%22:3,%22data%22:%7B%22name%22:%22mastodon-host%22,%22template%22:%22mastodon.social%22,%22templateType%22:%22legacy%22%7D,%22type%22:%22defineTemplateTag%22,%22isEnabled%22:true,%22uuid%22:%2221110F68-1446-4EE8-9893-F0AFBFAE6743%22%7D,%7B%22platforms%22:3,%22data%22:%7B%22template%22:%22Mastodon%22,%22name%22:%22credential-id%22,%22templateType%22:%22legacy%22%7D,%22type%22:%22defineTemplateTag%22,%22isEnabled%22:true,%22uuid%22:%22E79892D6-A3E7-4651-B405-F8EDFAF26E7C%22%7D,%7B%22platforms%22:3,%22data%22:%7B%22template%22:%22%5B%5Bselection%5D%5D%22,%22name%22:%22status%22,%22templateType%22:%22legacy%22%7D,%22type%22:%22defineTemplateTag%22,%22isEnabled%22:true,%22uuid%22:%2288795BC3-EB2E-458F-AABD-93E665FEA586%22%7D,%7B%22platforms%22:3,%22data%22:%7B%22script%22:%22%5C/%5C/%20grab%20host-id%20from%20tags%5Cnlet%20host%20%3D%20draft.processTemplate(%5C%22%5B%5Bmastodon-host%5D%5D%5C%22)%5Cnlet%20credentialID%20%3D%20draft.processTemplate(%5C%22%5B%5Bcredential-id%5D%5D%5C%22)%5Cn%5Cn%5C/%5C/%20define%20a%20variable%20with%20the%20contents%20of%20the%20selection%20(or%20the%20entire%20draft%20contents%20if%20no%20text%20is%20selected)%5Cn%5Cnlet%20mastostatus%20%3D%20draft.processTemplate(%5C%22%5B%5Bstatus%5D%5D%5C%22)%5Cn%5Cn%5C/%5C/%20validate%20values%5Cnif%20(host.length%20%3D%3D%200%20%7C%7C%20host%20%3D%3D%20%5C%22your.mastodon%5C%22)%20%7B%5Cn%5Ctalert(%60Mastodon%20host%20must%20be%20configured%20to%20run%20this%20action.%5Cn%5CnEdit%20action%20and%20set%20your%20Mastodon%20host%20name%20(like%20%5C%22mastodon.social%5C%22)%20as%20the%20template%20value%20in%20the%20first%20%5C%22Define%20Template%20Tag%5C%22%20action%20step.%5Cn%60)%5Cn%5Ctcontext.cancel()%5Cn%7D%5Cn%22,%22allowAsync%22:%22false%22%7D,%22type%22:%22script%22,%22isEnabled%22:true,%22uuid%22:%22E4D56727-E9FC-4892-990B-0F492EC69E75%22%7D,%7B%22platforms%22:3,%22data%22:%7B%22script%22:%22%5C/%5C/%20create%20Mastodon%20instance%5Cnlet%20m%20%3D%20Mastodon.create(host,%20credentialID)%5Cn%5Cn%5C/%5C/%20post%20to%20the%20%5C/statuses%20endpoing%5Cnlet%20path%20%3D%20%5C%22%5C/api%5C/v1%5C/statuses%5C%22%5Cnlet%20data%20%3D%20%7B%5Cn%5Ct%5C%22status%5C%22:%20mastostatus,%5Cn%5Ct%5C%22visibility%5C%22:%20%5C%22public%5C%22%5Cn%7D%5Cnlet%20response%20%3D%20m.request(%7B%5Cn%20%20%5C%22path%5C%22:%20path,%5Cn%20%20%5C%22method%5C%22:%20%5C%22POST%5C%22,%5Cn%20%20%5C%22data%5C%22:%20data%5Cn%7D)%5Cn%5Cnif%20(!response.success)%20%7B%5Cn%5Ctconsole.log(%60Post%20Failed:%20$%7Bresponse.statusCode%7D,%20$%7Bresponse.error%7D%60)%5Cn%5Ctcontext.fail()%5Cn%7D%5Cn%5Cn%5C/%5C/%20define%20a%20template%20tag%20with%20the%20resulting%20status's%20URL%5Cnelse%20%7B%5Cn%5Ctconsole.log(%60Posted%20to%20Mastodon:%20$%7Bresponse.responseData%5B%5C%22url%5C%22%5D%7D%60)%5Cn%5Ctdraft.setTemplateTag(%5C%22mastolink%5C%22,%20response.responseData%5B%5C%22url%5C%22%5D)%5Cn%7D%22,%22allowAsync%22:%22false%22%7D,%22type%22:%22script%22,%22isEnabled%22:true,%22uuid%22:%2214032709-A11D-43FD-B7C1-5868288006C3%22%7D,%7B%22platforms%22:3,%22data%22:%7B%22template%22:%22%5B%5Bmastolink%5D%5D%22,%22writeType%22:%22replace%22,%22templateType%22:%22legacy%22%7D,%22type%22:%22clipboard%22,%22isEnabled%22:true,%22uuid%22:%2220D209A3-DBAA-4040-A488-A1F3DDB1C72D%22%7D,%7B%22platforms%22:3,%22data%22:%7B%22template%22:%22%5B%5Bstatus%5D%5D%5Cn-%20%5BMastodon%5D(%5B%5Bmastolink%5D%5D)%22,%22templateType%22:%22legacy%22%7D,%22type%22:%22insertText%22,%22isEnabled%22:true,%22uuid%22:%2256EE86CC-FEB4-4BCF-A687-93B8B2AB2E4D%22%7D%5D,%22shouldConfirm%22:false%7D