What resources would you recommend to pick up AppleScript. I come with a traditional C/C++ with Objective-C background.
I am also looking for tips on how to develop better and get faster documentation from the script editor. A sample tip would be 'lookup the sdef file of the app you want to script.
I learned from AppleScript: the Definitive Guide. The free documentation available online at that time was quite confusing and incomplete, but that book taught me everything I needed to know. I'm not sure if the docs have improved since then (2005-ish).
As for tips on getting documentation, the script editor's "Open Dictionary" command is about the only documentation you'll get for most applications.
I recommend Applescript: The Definitive Guide like Ryan Ballantyne. Apple's own documentation is very good: Scripting and Automation: Applescript. I would seriously recommend reading lots of Applescript code as well, this is as important, if not more important, than reading these other resources. It is important to get a feel for what makes good and bad Applescript because there is an ocean of difference in readability between the good and the bad. You can find lots of code to read in Apple's material and at macscripter.net.
If you are going to be doing any, even remotely, serious development with Applescript, I highly recommend getting a copy of Script Debugger from Late Night Software.
Apple's own Script Editor and Applescript Studio (which is simple Script Editor wrapped in Xcode) offers no debugging tools, you'll rely solely on their (sometimes esoteric) error messages and your own cowboy debugging (the "log" command). Script Debugger picks up where Script Editor leaves off—proper debugging, code stepping, code completion—and also runs scripts much faster. I can learn a lot about how a an unfamilar application implements Applescript with Script Debugger because the dictionary reader will actually give the exact syntax needed to use a command in most cases.
I agree with the folks above. Start with Soghoian's book. Very good. And then The Definitive Guide. Also, get on the Applescript Discussion list. Very good, with the author of the Definitive Guide being a major contributor to that.
And get ScriptDebugger 5. Absolutely necessary for serious Applescripting. I use it to automate Photoshop, Filemaker, and my Mac do to pretty complex things in managing photos and metadata for my employer.
Another suggestion: while reading up on AppleScript, take a look at Appscript which makes the Apple Event technology underneath AppleScript available in Python, Ruby, or even Objective-C. Why? Many people find the AppleScript language itself lacking compared to more modern languages like Python or Ruby. But whichever way you choose, be prepared for a certain level of frustration. Much of the power of Apple Events and scripting comes from the richness of the data models that AppleScript-able applications can implement. Unfortunately, every AppleScript-able application has its own implementation quirks and often there is a fair amount of hunting and pecking guesswork until you find the incantation that works for a particular operation. HAS touches on some of this here.
Appscript also provides some developer tools, like ASDictionary which exports applications' terminology as plain text or HTML files and in AppleScript or appscript formats.
http://osxnotes.net/applescript.html: notes, scripts, and AppleScript oneliners
https://developer.apple.com/library/mac/documentation/applescript/conceptual/applescriptlangguide/AppleScriptLanguageGuide.pdf
http://www.apeth.net/matt/downloads/ASTDG2Scripts.txt: example scripts from AppleScript: The Definitive Guide
http://www.amazon.com/Learn-AppleScript-Comprehensive-Scripting-Automation/dp/1430223618: my favorite book about AppleScript
http://www.cs.utexas.edu/~wcook/Drafts/2006/ashopl.pdf
http://www.cs.utexas.edu/~wcook/papers/AppleScript/AppleScript95.pdf
http://dl.acm.org/ft_gateway.cfm?id=1238845&type=pdf&path=%2F1240000%2F1238845%2Fsupp%2FAppleScript%2Epdf&supp=1&dwn=1&CFID=334275816&CFTOKEN=16694215
This isn't exactly a good place to start, but the document that I found most useful was a discussion on the design of AppleScript written by one of its original designers.
It mostly talks about the evolution of AppleScript from an idea to an implementation. There's a technical part in the middle, though, that really glued a lot of things together for me. I was interested to learn that most of AppleScript's design stemmed from limitations in MacOS at the time. There's also a bit at the end reflecting on how AppleScript has fared over the years.
I'm trying to learn as well.
Currently reading http://macscripter.net/viewtopic.php?id=24729
It's really good. But the link in the post is broken, so you have to search for the next post.
And my next stop is: http://mac.appstorm.net/how-to/applescript/the-ultimate-beginners-guide-to-applescript/
I'm in the middle of AppleScript 1-2-3 by Sal Soghoian who is in charge of the AppleScript program at Apple; step-by-step, good
Related
Is there a way to do the tasks that Apple Script allows without doing system("osascript ...")? In other words, what does osascript do under the hood?
It links with libDiagnosticMessagesClient, libEdit, AppKit, Carbon, Foundation, ApplicationServices, CoreFoundation and CoreServices so the answer must lie in one of those.
What vadian says. Calling directly into AppleScript via the AppleScript-ObjC bridge is by far the least awful option available.
AppleEventManager/NSAppleEventDescriptor/NSAppleScript/NSUserAppleScriptTask/OSAKit all lack good high-level APIs and documentation and are a PITA to work with. Scripting Bridge and JavaScript for Automation are broken obfuscated crap; not a fit alternative for anything more than the most trivial tasks. Appscript and its spinoffs are no longer supported. Apple (belatedly) fired its Mac Automation PM and dissolved the team back in 2016, and the whole stack is already starting to bitrot, so it's not really worth investing large amounts of time if you can avoid it.
AppleScript may suck as a language, but it's the only supported option that speaks Apple events right, and the only one that has documentation and community support worth a damn. Which makes a huge difference when you get stuck on how to control individual apps. (Which you will. A lot.)
ASOC takes away 90% of the pain of calling into AS from ObjC or ObjC-bridged languages. Quick how-to for ObjC/Python here; if you're on Swift it may require a bit more boilerplating, but a web search should turn up info on how to do that.
Ah looks like it uses the Apple Event Manager (and OSAscript stands for Open Scripting Architecture).
More info here. Also it looks like there is something to generate an easier API than using the event manager directly - the scripting bridge.
I am very new to making applications, and using Xcode, so I don't know much about it... I'm using Xcode 5.0.2 to attempt to create a basic osx application which will allow the user to search through a list of built in scripts, select the ones they would like to run, and push a button to run the scripts. I have several scripts already, all of which have the extension .scpt. i wrote the scripts using applescript editor.
From searching this website, and the rest of the internet, i haven't found a clear, step by step answer of what to do. I know that in order to run the shell script, there must be an interface button linked to an action in the implementation file, which is what will execute the script.
What is the action i have to put in the implementation file?
How do i link the button to the action?
where do i put my .scpt files?
I have absolutely no code written in Xcode, it is nothing but a blank new project.
I don't have much experience with Cocoa apps, if you have experience with Visual Studio this is nothing like it, I started by looking some videos from the link below, they're really helpful, he also provide a full course for Objective-C.
http://www.youtube.com/playlist?list=PLE83F832121568D36
I hope this helps!
There is a huge amount of aspects to the problem you are trying to solve. Honestly, connecting the NSButton to an Action is just taking the first (small) step! Just a few of the aspects you may encounter:
How are the files executed? (your main question)
How is the selection interface set up?
How to read from the files? How to process the data you read?
What kind of actions will your scripts perform? What is in fact allowed from within a Cocoa app? (I have no idea myself to be honest)
Each one of these suggests potential SO questions in itself.
I would suggest that you familiarise yourself with the environment and the language a bit before taking big leaps. Take some time (a few days at least) and follow some tutorials, program some simple apps. The link provided in the other answer is in fact a good one, AppleProgramming tutorials are easy to follow. You may also find Apple's Objective-C intro useful.
What is applescript and what is it used for?
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).
This means that, as Philip Regan described, you can get an application like Photoshop to perform a whole bunch of repetitive photo modifications and then tuck those photos away in a folder, for example.
Other than that, one of the notable features of Applescript is its "English-like" syntax. Apple intended for it to be used by everyday people and tried to make its syntax as close to English as they could. This intention ran into a lot of problems, not the least of which was getting the people who were creating Applescript dictionaries for their applications to respect this goal. Apple also originally intended for there to be an Applescript for other human languages as well and there was work done on a "French Applescript" if I recall correctly.
There are now libraries in scripting languages like Python and Ruby for interfacing with Applescript so you can control the applications using Python or Ruby syntax and not using Applescript syntax (which can be extremely annoying to learn for someone coming from a programming background because of its irregularities and "foreignness").
Apple's latest move to bring application scripting to the everyday user is Automator. I suggest you try it out, as it can be quite useful if your aims are encompassed by things everyone does (keep copies of webpages, etc, etc,)
AppleScript is a scripting language that can be used to automate actions on Macintosh computers.
Examples of actions that can be automated with AppleScript include filesystem operations, textual data parsing, running programs and invoking program functionality.
Applescript Wikipedia Entry is a good start
While I concur with the rest of the responders here—there are far too many other websites that have this information—I will tell you what I, personally, actually do with it to hopefully give a more practical understanding of what it can do as opposed to the academic or marketing definitions you'll get at other sites...
I manage a production department for a publishing company and I have dozens upon dozens of scripts that allow me to streamline and/or automate all sorts of processes including:
fully automated page layout of marketing materials, contact sheets, and simple book designs using Excel, XML, and InDesign.
large scale image conversions (typically hundreds of images) with Illustrator and Photoshop.
automatic clean up of files (names, types, and some folder structures) to prep them for archiving.
Essentially, I use Applescript to automate any repetative task so that my folks can do better things with their time than repeating the same mindless mouse clicks over and over again. We just drop the files onto the slave Mac, start the script, and it beeps when it's done.
Is there an example for a project a GUI fro script generation?
The idea is to let a non-programmer use a front end to enter command and simple logic that will translated to runnable
scripts.
The programming language does not meter.
thanks
I would use Qt + python, but the constrains you give are too general. simple logic could not be simple at all.
One of the best example of a GUI that generates scripts that I've seen so far is Apple's Automator. It's good not in the sense that it is has lots of features but that it is intuitive enough that many non-programmers use it to automate tasks. It is basically a flashy implementation of the unix pipe paradigm.
Another successful tool in term of getting non-programmers to write programs is Adobe Photoshop's Actions. It also basically emulates the unix pipe paradigm.
I've personally never seen anything that breaks the pipe paradigm successfully convince non-programmers to write programs. Apart from Excel spreadsheet equations of course - but that is just horrifying to write programs in.
There's no script behind the scenes, but the Grasshopper plug-in for the Rhinoceros CAD system allows you to create algorithms purely visually.
Grasshopper User Forums
It's got an extensive Video and Image gallery which often features the GUI.
I assume you ask for education purposes. Then LOGO is a good option (targeted towards children though).
Edit:
As you say, you want such a thing for an enterprise-like application. I'd go for some markup format such as YAML or XML. The script would be directly editable and be in a well-known language such as Python or Groovy. There might be existing GUI tools for markup languages. If you take this approach, please let me know good examples of such GUI tools.
Specifically for business rules of course there are things like Drools.
OK,
I want to create a windows shell extention that sits in the file menu much like the "Tortorise SVN" menu.
Does anyone know where I'd begin, a good article, or what interfaces to implement?
Thanks!
It's pretty straight forward actually. It's about a 3-4 step process. You didn't specify what language you were using.
Here's how to do it in native code:
http://www.kbcafe.com/articles/HowTo.Shell.pdf
Here's how to do it with .NET. Note that it is essentially the same as doing it with native code.
http://www.theserverside.net/tt/articles/showarticle.tss?id=ShellExtensions
Ah... Shell extensions... they can be a real pain in the butt if they're complicated, but you can do so much neat stuff. A great place to start is Mike Dunn's Complete Idiot's Guide To Writing Shell Extensions on codeproject.com.
There's an O'Reilly book called VB Shell Programming which goes into the API's in some depth. As the title suggests, it's aimed at Visual BASIC, but the API's are exposed through COM and the techniques discussed in the book are applicable for pretty much anything that supports COM. A quick look on Amazon.com suggests you can probably pick up a secondhand copy for a few dollars.
Avoid codeproject (for kids, full of bugs) and read the complete doc of MSDN on SNE.