How to write your own Automator Actions...

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
As soon as I get one evening spare I shall put a little tutorial here.

It will not cover everything, but it will be a good starting point for those that want to learn...

regards

Ric
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Have got a spare evening tonight so, I will be starting this article later tonight...Wednesday 9th November !

regards

Ric
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Before we start...

...back up your Mac !

(For no other reason, than you should!)

Now go to Apple Developer Website and sign up...just for the basic Account it's free !!! You have to be a member to Download !!!

Now, you need to either download the latest version of Xcode (Developers Tools !) from here, latest version. or load it on to your Mac from the supplied DVD that came with it, you will more than likely have to download !

Download vers 2.1, not the pre release 2.2 !

Now get yourself a coffee, it's a 800mb download !
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
You should have had enough time to have had a read of a few bits...

...so we shall continue tomorrow night !
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
...off we go again.

First you need an idea !

Well we are are going to use the "Make Alias" Action that I made earlier...

Now we need to open Xcode.

Then goto the File Menu and click "New Project"

Now you have some choices...


Xcode003.jpg



This will be an AppleScript Automator Action...

...in Xcode you can 'make' 3 types of Actions, it depends on your needs and what language you want to work in.

The three choice are...

1) AppleScript Automator Action
This project builds an Automator action using AppleScript.

2) Cocoa Automator Action
This project builds an Automator action using Cocoa.

3) Shell Script Automator Action
This project builds an Automator action using shell scripting.
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Now you need to name it, Xcode defaults to saving your 'Projects' into your home directory...


Xcode004.jpg
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
You should now be presented with a screen like this...


Xcode005.jpg



I know you're probably thinking aaaaaahhh, what's all that then !
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Well I'm not going to tell, not yet any way, that would take a whole book !

What I am going to explain, is all the bits that we are interested in...

...first

The top bar, "Toolbar"

Xcode006.jpg


This can be customised to how you want, mine doesn't normally look like this, but this 'is' the default ToolBar that you should see !

There's nothing here that you need to change, until you know a bit more. But the important bits are...

On the left:

Make Alias
Active Target

This is the name of our "Target" the target is the 'bit' that we are making...in normal circumstances this would be an Application...but we are making an Action in this case !

You can have more than one Target, but this is not something you need to worry about now, it is not needed for building an Action !

Action

Like in other Apps, it allows easy access to useful menu's and shortcuts. For now you don't really need it.

'Build' & 'Build and Go'

Now we're getting some where...

These buttons do what they say...

Build...this builds your 'Project' once all the elements have been made you click on the Build button and Xcode compiles your Project into the 'Target'.

Your new Project, whether it be an Application, Action, ScreenSaver etc would now be available to test.

Sometimes when you press build...Xcode will 'not' compile the Project because it finds errors in your code etc. This is were you move on to debugging !

Because we are making an Automator Action, we will use the 'Build and Go' button.

When we press the BaG button (BaG) Xcode will compile the Action, and then open Automator and place our Action in it so that we can test...

...try it, even though, all we have done so far is open Xcode, picked a Template and given it a name...

Click the BaG button and watch...amazing !

You should see something like this !


Automator001.jpg
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
You have now compiled your first Automator Action !

You can even drag it in if you want !

Automator002.jpg


Aren't Apple nice ! They give you the software and then they do nearly all the work for you...

...now we need to make it do something !!!
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
First the interface...

...double click the file "main.nib (English)"


Xcode007.jpg



This will launch another program called "Interface Builder"...
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Interface Builder is normally one of the Fun bits of developing...

This is where you get to visually build your project.


Interface Builder001.jpg
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Unfortunately in this Action we don't need to use Interface builder at all !

There is more about Interface Builder in this thread.

Get yourself a coffee and just have a play with Interface Builder if you want !

Just don't save anything you do...for now.
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Coffee break over...

Now because this Action that we are developing has no 'user' input we don't need to create a user interface...

Have a look at some of the supplied Actions and you will see what I mean...


This has a User Input

Automator003.jpg




This has No User Input

Automator004.jpg
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
So because we 'don't need' a user interface, we can quit out of Interface Builder, back to Xcode and delete the "main.nib (English)" file.



Xcode008.jpg


When presented with the next dialog box click "References and Files".
 

Ric

Joined
May 14, 2004
Messages
4,260
Reaction score
5
Do a save, then up to the 'Build Menu' and click 'Clean All Targets' this removes any elements that have been compiled, so when we do the next BaG it will be done using the elements that are now in our Project.

When you click 'Clean All Targets' a dialog box pops up...

"Also remove all Precompiled headers" should be ticked, then press the clean all targets button...

Xcode009.jpg



If you don't do the Clean...then when you do the next BaG it will look exactly as before !



On the next then a BaG... (Build and Go !)

...you should now see something like this in Automator.

Automator005.jpg


As you can see, it's now shrunk in size, the same as the Eject Disk Action...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top