Send to clipboard the selected text in the browser, the source URL and the current date and time

Almost every day I find something interesting in a web site which I usually copy and paste it inside a wiki page. Moreover, I insert the URL of the web page and the current time and date. An example is the following:

AppleScript’s “big advantage” over other scripting languages (which, frankly are much better to use for most tasks) is that it can automate the action of other applications on your Mac (as long as the developer has provided an AppleScript dictionary). (http://stackoverflow.com/questions/1317497/what-is-applescript-and-what-is-it-used-for/1317498#1317498 – [[2013-02-22]], 12:56)

I enclose the date in double brackets because that way a link is created to the page with the title “2013-02-22″ in which I keep my journal for the specific day. An additional bonus created from the link to the specific date is that when I visit the wiki page of that date, I can see a list of all of the pages that have a link to that page. This list is a good indicator of the subjects that I dealt with that day! This list is created by the following DynamicPageList query: {{#dpl: linksto = 2013-02-22 }}

Naturally, I wanted to automate the whole process so I created one bookmarklet for Firefox and one AppleScript for Google Chrome. The only difference between the two is that the AppleScript sends all the data automatically to clipboard while in Firefox the data will be shown in a separate window and then you need to press control + C and close the widow by pressing either Ok or Cancel.

The AppleScript is the following:

Click here to open the source code in AppleScript Editor

Update (2014-06-22): the above script at the moment does not work on Google Chrome. Actually you cannot execute any JavaScript code using AppleScript. For example the following simple script does not compile:

The same AppleScript for Safari is the following:

Click here to open the source code in AppleScript Editor

The same AppleScript for Firefox is the following:

Click here to open the source code in AppleScript Editor

Finally, the bookmarklet is the following:

You can drag and drop the bookmarklet to your bookmarks bar.

10 Responses to “Send to clipboard the selected text in the browser, the source URL and the current date and time”

  1. John Burrows says:

    This is great! Do you know how to make something like this for Safari?

  2. malkele says:

    Hi John,

    thanks for a great collection of tools and thoughts about workflow. Made use of a bookmarklet for FF and an AppleScript for Chromium. However, could not rewrite the AppleScript for FF and, when I tried, I was told that there is a syntax error: 3rd line, the term “tab” is highlighted, (I translate) ” a line-ending is expected here, instead an attribute is met with”. Not being AppleScript savvy I was stumped… In Chromium the AppleScript works flawlessly. Any ideas? Thanks.

  3. john says:

    Nice job, but the date interpretation is incorrect. I used your bookmarklet on 2014-04-02 at 22:34 SGT, but here’s the results:
    (http://www.organognosi.com/send-to-clipboard-the-selected-text-in-the-browser-the-source-url-and-the-current-date-and-time/#codesyntax_2 – [[2014-03-02]] Wednesday, 22:34)

  4. doug says:

    hello, i can not figure how to use the script for chrome!?
    i opened it in applescript editor and saved it in chrome scripts folder. but i think that is not the proper way. can you please explain me how should i do it?

  5. pguilford says:

    Hello. The applescript would be great for my studies, but I use Safari more often than Chrome. How might I change this for use with Safari? When I change tell application “Google Chrome” to “Safari” I get a syntax error telling me that expected the end of a line but found class name. It highlight the “tab” in “activate tab” on the thrid line. best regards.

    • The same script for Safari is the following:


      set theClip to ""
      tell application "Safari"

      set theClip to do JavaScript "(function(){clip = window.getSelection();
      url = location.href;
      var brackets = \"\\[\\[\";

      var myDate = new Date();
      var year = myDate.getFullYear();
      var month = myDate.getMonth();
      if(month <= 9)
      month = month+1;
      month = '0'+month;
      var day= myDate.getDate();
      if(day <= 9)
      day = '0'+day;
      var prettyDate = year +'-'+ month +'-'+ day;
      var minutes = myDate.getMinutes();
      if(minutes <= 9)
      minutes = '0' + minutes;

      var hours = myDate.getHours();
      if(hours <= 9)
      hours = '0' + hours;
      theFinalString = clip + \" (\" + url + \" - \" + brackets + prettyDate + \"]] \" + hours + \":\" + minutes + \")\";
      return theFinalString;}());" in document 1

      set the clipboard to theClip
      end tell

Leave a Reply