JavaScript on OSAScript

macos osascript
Created on 2015-05-27 Last Modified 2018-06-26


Example

Display Notification

#! /usr/bin/osascript -l JavaScript
app = Application.currentApplication();
app.includeStandardAdditions = true;
app.displayNotification('Hello, world', {withtitle: 'Title'})

example

// alfred workflow
// convert Google Chrome active tab to markdown link
function run(argz) {
  var app = Application.currentApplication();
  app.includeStandardAdditions = true;
  var Chrome = Application('Google Chrome');
  var activeTab = Chrome.windows[@0].activeTab;
  var result = '[' + activeTab.title() + '](' + activeTab.url() + ')';
  app.setTheClipboardTo(result)
  return result
}
// alfred workflow:
// email link of Google Chrome active tab
function run(argz){
  var Chrome = Application('Google Chrome');
  var activeTab = Chrome.windows[@0].activeTab;

  var title: activeTab.title();
  var url = activeTab.url();
  var mdl = '[' + title + '](' + url + ')';

  // cos I use Airmail as email client
  var Airmail = Application('Airmail');
  message = Airmail.OutgoingMessage().make();
  message.subject = activeTab.title();
  var htmlcontent = '';
  htmlcontent += '<a href="' + url + '">' + url + '</a>';
  htmlcontent += '<br><br>';
  htmlcontent += mdl;

  message.htmlcontent  = htmlcontent;

  Airmail.compose(message);
  Airmail.activate();
}

comments powered by Disqus