Open URLs and File-URLs

Posted by Chris Grieser (armenaton), Last update about 1 year ago


about 1 year ago

small bugfixes

show all updates...

about 1 year ago

small bugfixes

about 1 year ago

also works on file hooks now

If text is selected, opens on URLs in the selection.
If no text is selection, opens all URLs in the whole draft.

Also works on URLs to the file system like file:///Users/myname/file.txt


  • script

    //checks ether there is an in selection at the moment
    if (editor.getSelectedText() == "") {
    	var textToCheck = draft.content; 
    } else {
    	var textToCheck = editor.getSelectedText();
    //identifies URL and opens all, URL-Regex from
    let URLmatches = textToCheck.match(/\b((?:[a-z][\w-]+:(?:\/{1,3}|[a-z0-9%])|www\d{0,3}[.]|[a-z0-9.\-]+[.][a-z]{2,4}\/)(?:[^\s()<>]+|\(([^\s()<>]+|(\([^\s()<>]+\)))*\))+(?:\(([^\s()<>]+|(\([^\s()<>]+\)))*\)|[^\s`!()\[\]{};:'".,<>?«»“”‘’]))/ig);
    if (URLmatches != null){
    	URLmatches.forEach(element => {
    		//checks if it is a file-hook
    		if (element.match(/file:\/\/\/[^\)]*/ig) != null){
    			draft.setTemplateTag("filepath", element);
    			if (element.match(/(.*)\/$/) != null) { draft.setTemplateTag("folder", "true") ;} ;
    		}	else {
    			app.openURL (element);
    } else {
    	app.displayErrorMessage("No URL or file URLs found");
    //archives when no selection was made
    if ((editor.getSelectedText() == "") && (URLmatches != null)){
    	draft.isArchived = true; 
  • runAppleScript (macOS only)

    -- AppleScript content
    -- Editing and testing in Script Editor recommended
    on execute(draft)
        tell application "Finder" 
    		open location "[[filepath]]"
    		if ("[[folder]]" = "true") then activate
    	end tell
    end execute


  • After Success Nothing
    Notification Error
    Log Level Info
Items available in the Drafts Directory are uploaded by community members. Use appropriate caution reviewing downloaded items before use.