[HN Gopher] AppleScript (2006) [pdf]
       ___________________________________________________________________
        
       AppleScript (2006) [pdf]
        
       Author : salgernon
       Score  : 48 points
       Date   : 2022-03-03 08:59 UTC (14 hours ago)
        
 (HTM) web link (www.cs.utexas.edu)
 (TXT) w3m dump (www.cs.utexas.edu)
        
       | leodriesch wrote:
       | I've recently wrote some AppleScript for some window management
       | and as someone with more experience with C-style languages I find
       | it's syntax deeply confusing.
       | 
       | It was more of a trial and error thing than anything else,
       | tutorials online worked more or less.
       | 
       | I see that it is incredibly easy to read, also for non-
       | programmers, but I find it really hard to write, at least as
       | someone that is not very into it.
        
       | russellbeattie wrote:
       | Apple desperately needs to kill AppleScript. Every year or so for
       | the past decade, I run into a problem and think, "Oh, I'll try
       | AppleScript" and as the saying goes, it rarely ends well. [1]
       | 
       | We NEED the functionality of desktop apps and services exposing
       | scriptable objects and methods. We do NOT need a "human language
       | based scripting language". Programming in Python, Java and
       | JavaScript have been taught at all levels of school for many
       | years now, with countless resources online. Anyone who would ever
       | have an interest in scripting their computer - the so-called
       | Power Users - already have been exposed to traditional
       | programming languages at some point in their lives and don't need
       | or want to use a "simplified" language.
       | 
       | So not only is AppleScript a bewildering, barely documented,
       | Through-the-Looking-Glass version of a programming language
       | ("'How do you know that I'm mad?' said Alice. 'You must be,' said
       | the Cat, 'or you wouldn't have come here.'"), but the impetus for
       | using such a language has totally disappeared, even if it wasn't
       | an unusable mess designed by autists on LSD.
       | 
       | 1. https://www.russellbeattie.com/blog/fun-with-the-os-x-
       | finder...
        
       | serverlessmom wrote:
       | I didn't realize AppleScript was still a thing, but here it is:
       | https://developer.apple.com/library/archive/documentation/Ap...
        
       | lostgame wrote:
       | AppleScript might be one of the single most bizarre and arduous-
       | to-write-in mainstream scripting/coding languages in history. I
       | can't say I'm a fan of such a literal interpretation of writing
       | code.
       | 
       | That being said, before I got a solid grasp on Obj-C and the (at
       | the time) OSX APIs like CoreImage, etc; it got me started on
       | writing Mac applications whereas otherwise I'd have had a much
       | rougher time with it.
       | 
       | Back when I'd made the switch from Windows to OSX in 2005 or so,
       | I had written an AppleScript and accompanying Xcode app to auto-
       | align desktop icons to the left, such as on the Windows desktop,
       | as it drove me nuts that they auto-aligned to the right. (Now I
       | prefer the right, lol...)
        
       | bobbylarrybobby wrote:
       | As terrible as AppleScript is as a language, it's really nice
       | that Apple even built a framework for apps to use to expose their
       | functionality to external scripts -- I'm not sure today's Apple
       | would have gone to the trouble. And now that you can use
       | JavaScript instead of AppleScript, with a more or less standard
       | way of translating calls between the two, scripting+automating
       | macOS is really painless.
       | 
       | I do wonder why the Shortcuts app seems to be reinventing the
       | wheel. You'd think the functionality an app exposed to
       | AppleScript would've been automatically made available in
       | Shortcuts, with Shortcuts being more or less a block-based
       | interface to the same scripting environment that AppleScript
       | uses, but that doesn't seem to be the case. Kind of an odd choice
       | to not build off their existing work there.
        
         | fiddlerwoaroof wrote:
         | It's also relatively easy to use the Scripting Bridge from any
         | language that can integrate with the objective-c runtime. I've
         | written a bunch of Mac automation in Common Lisp
        
         | alwillis wrote:
         | I had to automate transforming some Excel data for a friend
         | recently and I did it using AppleScript.
         | 
         | Turns out it's not as bad as the prevailing HN narrative. It
         | does require a change in mindset but once you get there, it's
         | actually quite nice, especially when using an app with a nicely
         | designed dictionary.
         | 
         | Like a lot of Apple's technology from the 90's, it was a
         | technology before its time. It certainly was pretty important
         | during Apple's near death experience in the late 90's due to
         | the publishing workflows that could only be done (at that time)
         | using AppleScript and Quark XPress, etc.
        
           | fzumstein wrote:
           | Have a look at xlwings (I am the creator), it's a Python
           | wrapper around AppleScript that follows closely the original
           | VBA object model, so won't require a change in mindset.
        
         | jhbadger wrote:
         | It's a "terrible language" in that it doesn't resemble most
         | languages currently in use, but it resembles Hypercard's
         | language Hypertalk a lot, so at the time it was created, this
         | was a good idea. Hypercard/Hypertalk made GUI programming
         | possible for non-technical people in a way that has not been
         | possible since.
        
         | crooked-v wrote:
         | > I do wonder why the Shortcuts app seems to be reinventing the
         | wheel.
         | 
         | Shortcuts is cross-platform, and so designed from the ground up
         | to work sanely under the limitations of both macOS and iOS.
        
           | mmerickel wrote:
           | I have plenty of shortcuts that work on iOS but don't work on
           | macOS. It's fun when you use siri on the mac and it tells you
           | it can't do something halfway through.
        
       | bouvin wrote:
       | AppleScript is not much of a general purpose programming language
       | (the syntax certainly takes a while to get used to), but for
       | automating stuff, sorting files into folders, and the like, it is
       | a nice tool. I have scripts that are indispensable to me, and
       | combined with Folder Actions it ensures that there are things
       | that Just Work.
        
       | lopis wrote:
       | Does this still exist? And is it actually "widely used" by any
       | MacOS apps?
        
         | duskwuff wrote:
         | Still exists, but support in modern macOS apps is pretty
         | spotty.
         | 
         | One app which does have surprisingly good AppleScript support
         | is Music, which exposes the library as a fully featured OSA
         | collection:                   tell application "Music"
         | play (some track whose genre is "Rock" and duration < 240)
         | end tell
         | 
         | Unfortunately, the scripting dictionary is kind of old, and
         | doesn't fully expose some newer features like "Up Next".
        
       | olliej wrote:
       | I implemented quick sort in AppleScript many years ago (to see if
       | I could, not because this is a good idea), and it was
       | excruciating. Very much the epitome of read only code :D
        
         | jtbayly wrote:
         | I wrote a fair bit of AppleScript. It always seemed like my
         | code was right, but it was wrong just as often as any other
         | programming language I use. It was just as inflexible and
         | demanding. That was frustrating, since reading it made it
         | _look_ like it was easy and it didn 't care how you wrote it.
         | 
         | But anyway, at least you could read the program and understand
         | it afterwards, whether you wrote it or not, whether you
         | understood all the things that had to be just so or not.
        
       | udbhavs wrote:
       | See also: Hyperscript (https://www.hyperscript.org)
        
       | pie_flavor wrote:
       | I lament the modern dearth of natural-language scripts designed
       | for normal people who have slightly higher engineering instinct
       | than average but otherwise just want to use their computer.
       | Different people notice the usefulness of such things in
       | different places, but for me it was Minecraft server
       | administration. You have thirteen year olds doing a 'banging on
       | the keyboard' level of management for game servers for eleven
       | year olds, and who do not know the first thing about programming
       | and would take years to get up and running with Java, but who
       | have added to the server dozens of commands and idiosyncratic
       | game mechanics with Skript, because Skript's language is so
       | fundamentally easy and approachable that just about anyone could
       | make just about anything in it that they could conceptualize of
       | the details for.
       | 
       | I really don't think AppleScript's primary application has
       | vanished like many people seem to think it has. Desktop software
       | may be on the decline, but that just means that something
       | equivalent for web needs to exist. Every other day you hear about
       | a business that had some major component, which finally broke,
       | being a giant kludge of an Excel sheet. Those things don't start
       | because they're the best tool for the job, they start because
       | Excel's approachable for non-programmers who can figure out how
       | to make an algorithm work as long as you don't call it an
       | algorithm or force them to start with stdio. Flash had that
       | property too, and the Internet is the lesser for its
       | disappearance; it took so little effort for an animation to be
       | turned into a game that so many animators decided to try. Nobody
       | ever bothers making things like that anymore because everyone's
       | internalized this idea that anything like programming is as hard
       | and as not worth targeting towards normal people as general
       | programming.
       | 
       | I don't know how to end rants.
        
         | imglorp wrote:
         | AS failed at natural language though.
         | 
         | The experience is exactly programming with more keywords.
         | There's still a rigid grammar and keywords have precise
         | meanings. You still have to look up what keywords are
         | available, what contexts to use them, what arguments they want,
         | etc etc. It's programming. Harder even.
         | 
         | Ideally there's a bunch of real conversational NLP with common
         | sense and context. This is really what you want:
         | find my firefox window         move it to the second workspace
         | on that desktop make slack to be the top window         close
         | all finder windows
         | 
         | we're not there yet
        
           | alwillis wrote:
           | I think you're overstating the difficulties.
           | 
           | One thing I liked about my recent stint with AppleScript were
           | the various synonyms I could use to express what I was doing,
           | depending on what made the most sense.
        
           | donatj wrote:
           | While we're not there for programming, I think we're getting
           | close with things like Alexa.
           | 
           | I'm always surprised when I'm at a friends house and they'll
           | ask Alexa to do something in a completely different syntax
           | than I use, and it works flawlessly.
        
         | pjot wrote:
         | I see it similar to self-selection.
         | 
         | Those interested will dig into the OS, then find Automator,
         | then find Apple Script, notice similarities to Minecraft
         | servers, and ultimately choose their own adventure.
         | 
         | I wonder though, if these features were more forward, how would
         | that shape what the "typical" user discovers? As Bradbury-esque
         | as that may sound...
        
         | haroldp wrote:
         | AppleScript was one of my first programming languages, way back
         | in the day. I still have an AppleScript I wrote that I use
         | every day on my MacBook. I'll say it was nice for a beginner
         | that it didn't use a lot of fiddly punctuation, like dollar
         | signs to start variable names, or semicolons to end statements.
         | But the language is only natural-ish. The syntax is just as
         | formal as python or anything else in how you must put it
         | together. It _looks_ easy, and maybe that is a virtue, but a
         | week into it you are looping over an array and de-referencing
         | the dictionary in each element. It 's still loops,
         | conditionals, operators, functions, typing, etc.
        
         | armchairhacker wrote:
         | The problem is that when you try to make programming use
         | natural language, it isn't natural language, it's an
         | amalgamation with unnatural "natural" language syntax which is
         | even more confusing than regular code.
         | 
         | Another issue is that when people create large programs with
         | this software it becomes unwieldy, because the developers
         | sacrificed scalability to try and improve accessibility. Even
         | real languages like Python and JavaScript suffer from this.
         | 
         | I might be biased as a programmer, but i doubt non-programmers
         | take any longer to learn code syntax than "natural" language
         | syntax. I think a way to get non-programmers into language
         | would be to adopt an existing language like Swift or Kotlin,
         | and add support for block-based syntax (since you can recognize
         | the syntactic constructs and remember how they work vs. having
         | to remember and recall) and lots of other built-in support
         | tools (like Copilot), especially for abstract concepts like
         | variables, custom structures, and closures.
        
       | gcanyon wrote:
       | It's important to distinguish Apple script the language from the
       | dictionaries of events that apps support. The language is fine.
       | It's a little different, and there are many features from modern
       | languages like Python that it could use.
       | 
       | But the main issue is not the language, but the event
       | dictionaries exposed by applications. I once spent most of a day
       | finding out that a "page" was not an element of a "document", but
       | a "spread" was, and a "page" was an element of a "spread". That
       | might have been in adobe pagemaker.
       | 
       | When the dictionary is clear, everything is fine. When it's
       | opaque, that's when things get sticky. To be clear, AppleScript
       | and app dictionaries are awesome -- just someone's also painful.
        
       | dnljrz wrote:
       | I remember showing my friend a few tricks with AppleScript when
       | he started working as a genius. Apparently his manager got mad at
       | him after a customer had complained about him writing a script as
       | they thought he was "hacking" them. Turns out the manager had no
       | idea what AppleScript was too.
        
       ___________________________________________________________________
       (page generated 2022-03-03 23:01 UTC)