SlideShare a Scribd company logo
1 of 23
Download to read offline
Reprocessed.org »


Scripting OS X
with Applescript,
without
Applescript.
Reprocessed.org »


With Ruby
instead
Reprocessed.org »


Hello, my name is
Matt
Reprocessed.org »


Why Applescript
isn’t Applescript
Reprocessed.org »

 • Applescript is Apple’s system-level inter-process
   scripting system
 • It’s actually made of two parts:
  • Applescript, the language
  • OSA – Open Scripting Architecture – which is the
    plumbing
 • Generally, when people ask, ‘is it Applescriptable?’,
   they actually mean, ‘does it accept Apple Events
   and expose a terminology dictionary for OSA
   clients to use?’ Clearly, the first is shorter.
Reprocessed.org »

 • Applescript looks a bit like this:
   tell application quot;Finderquot;
      empty the trash
   end tell

 • All pretty simple, right? Not quite. Check these two
   radically different lines out:

   get words 1 thru 4 of quot;now is the winter of our
   discontentquot;

   get text from word 1 to 4 of quot;now is the winter
   of our discontentquot;
Reprocessed.org »


Sort of like an
API
Reprocessed.org »

 • You get a way to stitch all sorts of things and apps
   on your Mac together in all sorts of interesting
   ways
 • This is so useful that the publishing industry relies
   on Applescript to tie together apps and processes
   into the editorial workflow stuff needed to get
   magazines and newspapers out the door.
 • You can do the stitching together of lots of separate
   things in a single script
Reprocessed.org »


Actually, mostly
like IPC
Reprocessed.org »

 • Under the hood, its OSA which makes all this
   possible. OSA allows apps to send Apple Events to
   each other, and defines standard ways to interpret
   the results, so you can send data types around the
   place
 • When you iterate across things in a script, you’re
   not really iterating across things in memory: Script
   Editor (or whatever script running OSA runtime
   you’re using) is firing Apple Events around the
   place and interpreting the results
Reprocessed.org »


It’s a query
Reprocessed.org »

 • What’s actually going on is more like SQL...
 • So, lets have a look...
Reprocessed.org »


Demo time...
Reprocessed.org »


The english-
likeness monster
Reprocessed.org »

 • As we’ve already seen, the english-likeness of
   Applescript the language gets complex. Particularly
   for programmers.
 • Multi-word tokens are just plain odd, and allowing
   apps and scripting additions to essentially redefine
   parts of the language syntax doesn’t help much
 • John Gruber goes into this at great length here:
   http://daringfireball.net/2005/09/
   englishlikeness_monster
 • So, is there a way to access the good stuff without
   the gut-wrenching terror?
Reprocessed.org »


Enter rb-
appscript / Watch
OSA surface from
the depths
Reprocessed.org »

 • Since Applescript is layered on top of OSA, in
   theory you could just use a different OSA runtime.
 • For once, theory ≈ practice...
 • There are low-level Apple Event modules for most
   dynamic languages, and for Python and Ruby,
   Hamish Sanderson has given us Appscript, which
   gives us a nice abstraction layer over the guts which
   actually makes use of those terminology
   dictionaries...
 • See http://appscript.sourceforge.net/ for the full
   story
Reprocessed.org »

 • Appscript takes away the pain of english-likeness
   by giving us a consistent interface and making a lot
   of the voodoo implicit stuff explicit
 • Believe me, you’ll appreciate this.
 • Appscript code looks a bit like this:
   app('TextEdit').documents['Read Me'].
     paragraphs[1].get()

 • As opposed to:
   tell application quot;TextEditquot;
      get paragraph 1 of document quot;Read Mequot;
   end tell
Reprocessed.org »


Munging phone
numbers in
Address Book
Reprocessed.org »

 • The critical bits:
   Appscript::app('Address Book').
     app.people.phones.get()
   => [a, bunch, of, number, objects]

   number = phone.value.get()

   phone.value.set(number)
Reprocessed.org »


Demo time...
Reprocessed.org »


Questions?
Reprocessed.org »


Thank you
matt@reprocessed.org
http://reprocessed.org/
Some code from Matt Neuberg’s excellent
Applescript: The Definitive Guide, published
by O’Reilly

More Related Content

What's hot

Asynchronous programming - .NET Way
Asynchronous programming - .NET WayAsynchronous programming - .NET Way
Asynchronous programming - .NET WayBishnu Rawal
 
Searching CPAN Offline
Searching CPAN OfflineSearching CPAN Offline
Searching CPAN Offlineacme
 
Hashstyling &Prelinks
Hashstyling &PrelinksHashstyling &Prelinks
Hashstyling &Prelinksguest6db481
 
Denetmen Bundle (Manage your routes like a boss!)
Denetmen Bundle (Manage your routes like a boss!)Denetmen Bundle (Manage your routes like a boss!)
Denetmen Bundle (Manage your routes like a boss!)Mustafa Ileri
 
Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Particular Software
 
Async-await best practices in 10 minutes
Async-await best practices in 10 minutesAsync-await best practices in 10 minutes
Async-await best practices in 10 minutesPaulo Morgado
 
Beyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingBeyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingFabio Tiriticco
 
Capistrano - automate all the things
Capistrano - automate all the thingsCapistrano - automate all the things
Capistrano - automate all the thingsJohn Cleary
 
Getting Started with Capistrano
Getting Started with CapistranoGetting Started with Capistrano
Getting Started with CapistranoLaunchAny
 
Backpressure in akka-streams
Backpressure in akka-streamsBackpressure in akka-streams
Backpressure in akka-streamsDaniel Sebban
 
community day 2013 - camunda-bpm-camel
community day 2013 - camunda-bpm-camelcommunity day 2013 - camunda-bpm-camel
community day 2013 - camunda-bpm-camelcamunda services GmbH
 
Cachopo - Scalable Stateful Services - Madrid Elixir Meetup
Cachopo - Scalable Stateful Services - Madrid Elixir MeetupCachopo - Scalable Stateful Services - Madrid Elixir Meetup
Cachopo - Scalable Stateful Services - Madrid Elixir MeetupAbel Muíño
 

What's hot (20)

Perl ides
Perl idesPerl ides
Perl ides
 
Asynchronous programming - .NET Way
Asynchronous programming - .NET WayAsynchronous programming - .NET Way
Asynchronous programming - .NET Way
 
C# & AWS Lambda
C# & AWS LambdaC# & AWS Lambda
C# & AWS Lambda
 
Searching CPAN Offline
Searching CPAN OfflineSearching CPAN Offline
Searching CPAN Offline
 
Hashstyling &Prelinks
Hashstyling &PrelinksHashstyling &Prelinks
Hashstyling &Prelinks
 
Denetmen Bundle (Manage your routes like a boss!)
Denetmen Bundle (Manage your routes like a boss!)Denetmen Bundle (Manage your routes like a boss!)
Denetmen Bundle (Manage your routes like a boss!)
 
Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps Async/Await: TPL & Message Pumps
Async/Await: TPL & Message Pumps
 
Async-await best practices in 10 minutes
Async-await best practices in 10 minutesAsync-await best practices in 10 minutes
Async-await best practices in 10 minutes
 
Beyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor ProgrammingBeyond Fault Tolerance with Actor Programming
Beyond Fault Tolerance with Actor Programming
 
Capistrano - automate all the things
Capistrano - automate all the thingsCapistrano - automate all the things
Capistrano - automate all the things
 
CAPISTRANO
CAPISTRANOCAPISTRANO
CAPISTRANO
 
Getting Started with Capistrano
Getting Started with CapistranoGetting Started with Capistrano
Getting Started with Capistrano
 
Backpressure in akka-streams
Backpressure in akka-streamsBackpressure in akka-streams
Backpressure in akka-streams
 
Capistrano
CapistranoCapistrano
Capistrano
 
community day 2013 - camunda-bpm-camel
community day 2013 - camunda-bpm-camelcommunity day 2013 - camunda-bpm-camel
community day 2013 - camunda-bpm-camel
 
Concurrency in ruby
Concurrency in rubyConcurrency in ruby
Concurrency in ruby
 
Flask vs. Django
Flask vs. DjangoFlask vs. Django
Flask vs. Django
 
Cachopo - Scalable Stateful Services - Madrid Elixir Meetup
Cachopo - Scalable Stateful Services - Madrid Elixir MeetupCachopo - Scalable Stateful Services - Madrid Elixir Meetup
Cachopo - Scalable Stateful Services - Madrid Elixir Meetup
 
Async/Await Best Practices
Async/Await Best PracticesAsync/Await Best Practices
Async/Await Best Practices
 
Computer programming k 12
Computer programming k 12Computer programming k 12
Computer programming k 12
 

Viewers also liked

Cocoa勉強会#43-Blocksを使う
Cocoa勉強会#43-Blocksを使うCocoa勉強会#43-Blocksを使う
Cocoa勉強会#43-Blocksを使うMasayuki Nii
 
Applescript
ApplescriptApplescript
ApplescriptMD5500
 
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作JavaScript で OS X を自動操作
JavaScript で OS X を自動操作Tomokazu Kiyohara
 
Xcode以外の開発環境 AppCodeの紹介
Xcode以外の開発環境 AppCodeの紹介Xcode以外の開発環境 AppCodeの紹介
Xcode以外の開発環境 AppCodeの紹介Akira Hayashi
 
タスクを喰らうど!
タスクを喰らうど!タスクを喰らうど!
タスクを喰らうど!Daisuke Miura
 
Quick Application Development with Web Frameworks
Quick Application Development with Web FrameworksQuick Application Development with Web Frameworks
Quick Application Development with Web FrameworksStratepedia Presentations
 
私の営業の失敗談
私の営業の失敗談私の営業の失敗談
私の営業の失敗談幸雄 村上
 

Viewers also liked (10)

Giran Sieges - Applescript com @leohackin
Giran Sieges - Applescript com @leohackinGiran Sieges - Applescript com @leohackin
Giran Sieges - Applescript com @leohackin
 
Cocoa勉強会#43-Blocksを使う
Cocoa勉強会#43-Blocksを使うCocoa勉強会#43-Blocksを使う
Cocoa勉強会#43-Blocksを使う
 
Applescript
ApplescriptApplescript
Applescript
 
JavaScript で OS X を自動操作
JavaScript で OS X を自動操作JavaScript で OS X を自動操作
JavaScript で OS X を自動操作
 
Xcode以外の開発環境 AppCodeの紹介
Xcode以外の開発環境 AppCodeの紹介Xcode以外の開発環境 AppCodeの紹介
Xcode以外の開発環境 AppCodeの紹介
 
タスクを喰らうど!
タスクを喰らうど!タスクを喰らうど!
タスクを喰らうど!
 
Text to-speech
Text to-speechText to-speech
Text to-speech
 
Quick Application Development with Web Frameworks
Quick Application Development with Web FrameworksQuick Application Development with Web Frameworks
Quick Application Development with Web Frameworks
 
Ning presentation
Ning presentationNing presentation
Ning presentation
 
私の営業の失敗談
私の営業の失敗談私の営業の失敗談
私の営業の失敗談
 

Similar to Scripting OS X with Applescript, without Applescript

Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic RevisitedAdam Keys
 
Alfresco in few points - Search Tutorial
Alfresco in few points - Search TutorialAlfresco in few points - Search Tutorial
Alfresco in few points - Search TutorialPASCAL Jean Marie
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholisticoscon2007
 
The Holistic Programmer
The Holistic ProgrammerThe Holistic Programmer
The Holistic ProgrammerAdam Keys
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Espen Brækken
 
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...Peter Hecker
 
RxSwift for Beginners - how to avoid a headache of reactive programming
RxSwift for Beginners - how to avoid a headache of reactive programmingRxSwift for Beginners - how to avoid a headache of reactive programming
RxSwift for Beginners - how to avoid a headache of reactive programmingMaciej Kołek
 
Opal chapter 4_a_new_hope
Opal chapter 4_a_new_hopeOpal chapter 4_a_new_hope
Opal chapter 4_a_new_hopeForrest Chang
 
Weird Plsql
Weird PlsqlWeird Plsql
Weird Plsqlwebanddb
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldKonrad Malawski
 
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"JSFestUA
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails FinalRobert Postill
 
Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009spierre
 
Cocoapods sane library management for xcode
Cocoapods   sane library management for xcodeCocoapods   sane library management for xcode
Cocoapods sane library management for xcodeleonardehrenfried
 
Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016 Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016 petecarapetyan
 
YAPC::EU::2009 - How Opera Software uses Perl
YAPC::EU::2009 - How Opera Software uses PerlYAPC::EU::2009 - How Opera Software uses Perl
YAPC::EU::2009 - How Opera Software uses PerlCosimo Streppone
 
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...phpbarcelona
 

Similar to Scripting OS X with Applescript, without Applescript (20)

Culture And Aesthetic Revisited
Culture And Aesthetic RevisitedCulture And Aesthetic Revisited
Culture And Aesthetic Revisited
 
Alfresco in few points - Search Tutorial
Alfresco in few points - Search TutorialAlfresco in few points - Search Tutorial
Alfresco in few points - Search Tutorial
 
Os Keysholistic
Os KeysholisticOs Keysholistic
Os Keysholistic
 
The Holistic Programmer
The Holistic ProgrammerThe Holistic Programmer
The Holistic Programmer
 
Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex Ruby on Rails (RoR) as a back-end processor for Apex
Ruby on Rails (RoR) as a back-end processor for Apex
 
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
JavaScript nicht nur für Programmierer: Einblicke in die weltweit am meisten ...
 
RxSwift for Beginners - how to avoid a headache of reactive programming
RxSwift for Beginners - how to avoid a headache of reactive programmingRxSwift for Beginners - how to avoid a headache of reactive programming
RxSwift for Beginners - how to avoid a headache of reactive programming
 
Opal chapter 4_a_new_hope
Opal chapter 4_a_new_hopeOpal chapter 4_a_new_hope
Opal chapter 4_a_new_hope
 
Weird Plsql
Weird PlsqlWeird Plsql
Weird Plsql
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming World
 
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
JS Fest 2019/Autumn. Alexandre Gomes. Embrace the "react fatigue"
 
DiUS Computing Lca Rails Final
DiUS  Computing Lca Rails FinalDiUS  Computing Lca Rails Final
DiUS Computing Lca Rails Final
 
Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009Sugar Presentation - YULHackers March 2009
Sugar Presentation - YULHackers March 2009
 
Cocoapods sane library management for xcode
Cocoapods   sane library management for xcodeCocoapods   sane library management for xcode
Cocoapods sane library management for xcode
 
Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016 Merged Automation Talk - Pete Carapetyan - Feb 2016
Merged Automation Talk - Pete Carapetyan - Feb 2016
 
Apache Zeppelin, Helium and Beyond
Apache Zeppelin, Helium and BeyondApache Zeppelin, Helium and Beyond
Apache Zeppelin, Helium and Beyond
 
YAPC::EU::2009 - How Opera Software uses Perl
YAPC::EU::2009 - How Opera Software uses PerlYAPC::EU::2009 - How Opera Software uses Perl
YAPC::EU::2009 - How Opera Software uses Perl
 
Ruby on Rails Presentation
Ruby on Rails PresentationRuby on Rails Presentation
Ruby on Rails Presentation
 
JavaScript for pupils
JavaScript  for pupilsJavaScript  for pupils
JavaScript for pupils
 
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
Text indexing and search libraries for PHP - Zoë Slattery - Barcelona PHP Con...
 

Recently uploaded

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAndikSusilo4
 

Recently uploaded (20)

Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Azure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & ApplicationAzure Monitor & Application Insight to monitor Infrastructure & Application
Azure Monitor & Application Insight to monitor Infrastructure & Application
 

Scripting OS X with Applescript, without Applescript

  • 1. Reprocessed.org » Scripting OS X with Applescript, without Applescript.
  • 5. Reprocessed.org » • Applescript is Apple’s system-level inter-process scripting system • It’s actually made of two parts: • Applescript, the language • OSA – Open Scripting Architecture – which is the plumbing • Generally, when people ask, ‘is it Applescriptable?’, they actually mean, ‘does it accept Apple Events and expose a terminology dictionary for OSA clients to use?’ Clearly, the first is shorter.
  • 6. Reprocessed.org » • Applescript looks a bit like this: tell application quot;Finderquot; empty the trash end tell • All pretty simple, right? Not quite. Check these two radically different lines out: get words 1 thru 4 of quot;now is the winter of our discontentquot; get text from word 1 to 4 of quot;now is the winter of our discontentquot;
  • 8. Reprocessed.org » • You get a way to stitch all sorts of things and apps on your Mac together in all sorts of interesting ways • This is so useful that the publishing industry relies on Applescript to tie together apps and processes into the editorial workflow stuff needed to get magazines and newspapers out the door. • You can do the stitching together of lots of separate things in a single script
  • 10. Reprocessed.org » • Under the hood, its OSA which makes all this possible. OSA allows apps to send Apple Events to each other, and defines standard ways to interpret the results, so you can send data types around the place • When you iterate across things in a script, you’re not really iterating across things in memory: Script Editor (or whatever script running OSA runtime you’re using) is firing Apple Events around the place and interpreting the results
  • 12. Reprocessed.org » • What’s actually going on is more like SQL... • So, lets have a look...
  • 15. Reprocessed.org » • As we’ve already seen, the english-likeness of Applescript the language gets complex. Particularly for programmers. • Multi-word tokens are just plain odd, and allowing apps and scripting additions to essentially redefine parts of the language syntax doesn’t help much • John Gruber goes into this at great length here: http://daringfireball.net/2005/09/ englishlikeness_monster • So, is there a way to access the good stuff without the gut-wrenching terror?
  • 16. Reprocessed.org » Enter rb- appscript / Watch OSA surface from the depths
  • 17. Reprocessed.org » • Since Applescript is layered on top of OSA, in theory you could just use a different OSA runtime. • For once, theory ≈ practice... • There are low-level Apple Event modules for most dynamic languages, and for Python and Ruby, Hamish Sanderson has given us Appscript, which gives us a nice abstraction layer over the guts which actually makes use of those terminology dictionaries... • See http://appscript.sourceforge.net/ for the full story
  • 18. Reprocessed.org » • Appscript takes away the pain of english-likeness by giving us a consistent interface and making a lot of the voodoo implicit stuff explicit • Believe me, you’ll appreciate this. • Appscript code looks a bit like this: app('TextEdit').documents['Read Me']. paragraphs[1].get() • As opposed to: tell application quot;TextEditquot; get paragraph 1 of document quot;Read Mequot; end tell
  • 20. Reprocessed.org » • The critical bits: Appscript::app('Address Book'). app.people.phones.get() => [a, bunch, of, number, objects] number = phone.value.get() phone.value.set(number)
  • 23. Reprocessed.org » Thank you matt@reprocessed.org http://reprocessed.org/ Some code from Matt Neuberg’s excellent Applescript: The Definitive Guide, published by O’Reilly