Custom Quick Posts Depending on Content Type
  • Dear RS,

    I am using the below format for Quick Posts, however need a way for the bookmarklet to pass into the Quick Post template specific URL variables depending on the type of post.

    <a href="http://www.somewebsite.com/latest" target="_blank"></a>
    [youtube450 275]
    [vimeo450 255]

    <blockquote></blockquote>

    via <a href="http://www.somewebsite.com/latest" target="_blank">http://www.somewebsite.com/latest</a>;

    For example, if it is a YouTube page, I want of the first three lines only line two to be used, and the YouTube video ID to be placed in between the youtube450 text. If it is a standard site, just to use the first of the three lines, and the youtube and vimeo lines to be excluded... Effectively I am in need of custom Quick Posts based on the type of page.

    Thank you.
  • Hi loyaliser - it's like you're reading out of my own notes for future ambitions of the Quick Posts feature. I definitely think something like what you're describing would be a great enhancement.
  • Agreed, in the mean time I think with some tweaking of the bookmarklet javascript code, I can probably at least pass the YouTube and Vimeo IDs into MarsEdit... And then just delete the stuff from the Quick Post not required... Will give it a try and post it here if it works.
  • I am trying to customize the bookmarklet for YouTube and Vimeo pages... But having trouble. On a YouTube and Vimeo page, the MarsEdit app does not fire up... Any other page works as normal... Any ideas?

    javascript:var url = 'marsedit:'; var currentURL = document.URL; url += 'title=' + encodeURIComponent(document.title); url += '&url=' + encodeURIComponent(currentURL); var selectedText = getSelection(); if (selectedText != '') url += '&text=' + encodeURIComponent(selectedText); if (currentUrl.indexOf('youtube.com')!=-1) {var ytQS = location.search.substring(1); url+='&ytID='+encodeURIComponent(ytQS);} else if (currentUrl.indexOf('vimeo.com')!=-1) {var vmQS = location.href.substring(7).split('/')[1]; url+='&vmID='+encodeURIComponent(vmQS);} document.location.href=url;
  • Hi - there is a minor coding issue in the bookmarklet code you pasted. "currentUrl" in two places should be "currentURL" instead (note case).

    I found this bug by using Safari's console in "Inspect Element" mode to monitor for JavaScript errors. Usually if something in a bookmarklet doesn't work right it boils down to a JavaScript bug that you can spot more easily if you have the Web Inspector's console open.
  • Corrected, but now when I place the variables in the Quick Post template, they do not resolve with the values:

    javascript:var url = 'marsedit:'; var currentURL = document.URL; url += 'title=' + encodeURIComponent(document.title); url += '&url=' + encodeURIComponent(currentURL); var selectedText = getSelection(); if (selectedText != '') url += '&text=' + encodeURIComponent(selectedText); if (currentURL.indexOf('youtube.com')!=-1) {var ytQS = location.search.substring(1); url+='&ytID='+encodeURIComponent(ytQS);} else if (currentURL.indexOf('vimeo.com')!=-1) {var vmQS = location.href.substring(7).split('/')[1]; url+='&vmID='+encodeURIComponent(vmQS);} alert(url); document.location.href=url;

    So vmID appears as #vmID# and ytID appears as #ytID# - is that because ME does not know to handle NEW variables in the URL ?

    Below is the template I am using:

    <a href="#url#" target="_blank"></a>
    [youtube #ytID# 450 275]
    [vimeo #vmID# 450 255]

    <blockquote>#body#</blockquote>

    via <a href="#url#" target="_blank">#url#</a>
  • Hi loyaliser - yes, that's right. Unfortunately MarsEdit currently only handles a fixed set of templates as shown in the Quick Posts editor. I'll consider the possibility of supporting arbitrary placeholders in the future. Hadn't thought of that before.
  • First stab at a custom AppleScript to do custom quick posts...


    on displayErrorMessage(s)
    display dialog (s) buttons {\"OK\"} default button \"OK\" with icon caution
    end displayErrorMessage

    property whiteSpaceAndNewlineCharacterSet : {tab, linefeed, return, space, character id 133}

    on trim(someText)
    repeat until first character of someText is not in whiteSpaceAndNewlineCharacterSet
    set someText to text 2 thru -1 of someText
    end repeat

    repeat until last character of someText is not in whiteSpaceAndNewlineCharacterSet
    set someText to text 1 thru -2 of someText
    end repeat

    return someText
    end trim

    global pageURL
    global pageTitle
    global selectedText

    tell application \"Google Chrome\"
    try
    copy selection of (active tab) of window 1
    set pageURL to (get URL of (active tab) of window 1)
    set pageTitle to (get title of (active tab) of window 1)
    on error errorMessage
    displayErrorMessage(\"ERROR ENCOUNTERED\") of me
    return
    end try
    end tell

    tell application \"System Events\"
    keystroke \"c\" using {command down}
    set selectedText to (the clipboard as text)
    end tell

    set selectedText to trim(selectedText)

    tell application \"MarsEdit\"
    make new document
    tell document 1
    set title to pageTitle
    set link to pageURL

    if pageURL contains \"vimeo.com\" then
    set idCode to text 18 thru 25 of pageURL
    set s to \"[vimeo \" & idCode & \" 450 255]

    \"
    set s to s & \"via &lt;a href=\\"http://vimeo.com/\" & idCode & \"\\" target=\\"_blank\\"&gt;vimeo.com&lt;/a&gt;\"
    set body to s
    else if pageURL contains \"youtube.com\" then
    set oldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to \"v=\"
    set idCode to text item 2 of pageURL
    set AppleScript's text item delimiters to oldDelims
    if idCode contains \"&\" then
    set oldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to \"&\"
    set idCode to text item 1 of idCode
    set AppleScript's text item delimiters to oldDelims
    end if
    set s to \"[youtube \" & idCode & \" 450 275]

    \"
    set s to s & \"via &lt;a href=\\"http://www.youtube.com/watch?v=\" & idCode & \"\\" target=\\"_blank\\"&gt;youtube.com&lt;/a&gt;\"
    set body to s
    else
    set unescapedURL to do shell script \"perl -e 'use URI::Escape; print uri_unescape(\\"\" & pageURL & \"\\")';\"
    set pageURL to unescapedURL

    if pageURL contains \"?utm\" then
    set oldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to \"?utm\"
    set pageURL to text item 1 of pageURL
    set AppleScript's text item delimiters to oldDelims
    end if

    set s to \"&lt;a href=\\"\" & pageURL & \"\\" target=\\"_blank\\"&gt;&lt;/a&gt;

    \"
    set s to s & \"&lt;blockquote&gt;\" & selectedText & \"&lt;/blockqoute&gt;

    \"

    set oldDelims to AppleScript's text item delimiters
    set AppleScript's text item delimiters to \"http://\"
    if pageURL contains \"instapaper.com\" then
    set theSite to text item 3 of unescapedURL
    else
    set theSite to text item 2 of unescapedURL
    end if
    set AppleScript's text item delimiters to \"/\"
    set theSite to text item 1 of theSite
    set AppleScript's text item delimiters to oldDelims
    set s to s & \"via &lt;a href=\\"\" & pageURL & \"\\" target=\\"_blank\\"&gt;\" & theSite & \"&lt;/a&gt;\"

    set body to s
    end if
    end tell
    end tell

    tell application \"Google Chrome\" to close active tab of window 1
Start a New Discussion

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!