Applescript Studio - How to...


Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Applescript Studio

Applescript Studio is a group of technologies that all work together to help you write your own software.

All are on you Panther or Tiger install CD or DVD. just copy over the developers tools folder.

Once you have loaded the developer tools, you can start building...

Launch, Xcode and select new project from the file menu (the screenshots are Tiger), then scroll down and for this example select "AppleScript Application". Fig 1.

Type in the project name as Fig 2, use whatever name you like ! Then press finish.

Don't worry we haven't really finished, we're just starting !

You should now have a project window, like Fig 3, (this is in Tiger).

I know....whoooaaaa....what's all this !!!

Don't worry it's not as bad as it looks...

...more tomorrow !
 

Attachments

Ad

Advertisements

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

Three "files/folders" in the project window are important for this Test App.

The 'Scripts Folder' see Fig4, this folder will contain the "Applescripts" that we are going to write for this Application !

If you click on this folder and then double click on the Script you will see something like Fig5 this will be, where we enter our Applescript.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The next folder we are interested in, is the 'Resources Folder'. Within here, as you can see as in Fig6 it contains a file called 'MainMenu.nib'. This nib file will contain our graphical elements such as the menus and windows for our little App.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The third 'file' is the 'Application File' itself, in this example it's the one at the end in red in Fig7, "Ric's Test App.app". This file doesn't exist yet, not until we 'build' the App a bit later on.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

The above are the basic building blocks that we are going to use to build our 'Applescript Studio App'. I am trying to keep this easy to follow and by doing so I am missing out some of the more technical aspects, but maybe we'll do a more complicated run through later !!!

more tomorrow...the fun bit, the interface builder !
 

Attachments

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

Next: The Interface Builder.

Reopen your project from before, and double click the 'MainMenu.nib', Fig8.

The Interface builder App will open, three 'Windows' should open up, shuffle them around so that you can see what you are doing, and open the inspector window from the 'Tools' menu.
 

Attachments

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

Have a look at the web browser that you are currently using, the 'Application itself' is a window...if you see what I mean. Every Application that you use is made up of Windows and Menus. This is what, in the simplest way, we have in front of us, in Interface builder.

We have a 'Main Window' and a 'Main Menu'.

WIMP....Windows ~ Icons ~ Menus ~ Pointer. Aqua is our GUI, Graphical User Interface of choice.

The three windows that have opened up should look like Fig11,12,13.
 

Attachments

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

The 'Window' can be resized to whatever size you want, for this example we are going to make a small floating window.

If the 'Cocoa-xxxxx' palette isn't already open, go to the Tools menu > Palettes >Show Palettes.

This palette contains all the 'bits' that we will need to make our App. Have a click through the icons across the top to see the various palettes, and what each one contains. we are interested in the one with the buttons on, second from the left.

The first 'palettte' that we are interested in is the 'Cocoa-Controls' palette. Fig14.

Drag a button across to the 'Window', Fig15.

Make sure the button is selected, and change the button name in the Inspector Window Fig16, to 'Run Daily'

Now make three more buttons, 'Run Weekly', 'Run Monthly' and 'Run All'. As Fig17.

Notice I have now made the 'Main Window' much smaller, and how I have arranged the buttons.
 

Attachments

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

As you dragged the buttons around, did you notice the guides ! They are very good for helping you align objects, so that everything looks nice.

It's starting to look a little more like an Application now.

Now we are going to add some text, and name the 'Main Window'. So that we end up with something like Fig18.
 

Attachments

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

To add the text, in this instance we are adding 'uneditable' text.

Now we are using the third from the left 'palette' Cocoa Text, drag across the 'Label Font Text' as Fig19.

Now edit that text box with the text from Fig18 (previous post). You will need to create three text boxes to create it exactly as Fig18. One for the main text, one for the 'This is just..' and one for the web address.

You can colour the text as you would in any word processor, just select the text and change the colour via the 'Colors' palette > Tools Menu. You can also resize, align etc.

Now to change the 'Main Window' name, just click the window and make sure nothing within it is selected, now change it via the Inspector. Fig20.

When we get a bit more confident we will have a look at a few other 'thing' we can do ... whilst the Inpector is still on the 'Main Window' change the 'Has Texture' to ticked ! Fig21.

Now our little Application should look like Fig22.
 

Attachments

Danster

New Member
Joined
Feb 12, 2005
Messages
267
Reaction score
8
Re: Applescript Studio

Hi

I had a crack at making a currency converter by looking at what you did for the temperature script and came up with this.

Ps. it can't convert numbers with Decimal points in such as £15.80 so maybe you can have a look and see where I've gone wrong :p
 

Attachments

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

Very good !
Code:
set text_returned to text_returned as real
Try this ! Your file was 'seeing the text entered' as an 'integer' and getting rid of the data after the decimal point

Lots of different way's of doing it, just need to allow AS to see the 'data' entered as a fraction/decimal.

Hope this helps.

Try pressing the control key and clicking in an open Script editor window and have a look at some of the scripts, they are very good for learning. Fig 3.
 

Attachments

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

One for you to work on when we have finished the tutorial, more tomorrow. Wifey calls...
 

Attachments

Danster

New Member
Joined
Feb 12, 2005
Messages
267
Reaction score
8
Re: Applescript Studio

Sweet, how did you make it look like that?
 

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

That's done in 'interface builder' you would then add your relevant bits of Applescript and voilla your own little App.

It is not a working version just an example to show you...when I finish writing this tutorial you will be able to build it yourself, easily, honest !

Will write more tutorial, once the anklebiter has gone to bed !

Playing choo choos, now !!! Gotta love brio smart track !!!
 

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

I'll finish tutorial tomorrow, just downloading Xcode 2.1 from Apple 700mb download !

Have just received the VTC Training videos on CD for AppleScript Studio, I'll let you know if they are any good once I've got round to watching them !

Have just received Xcode 2 book and a new AppleScript book to...reviews to follow both look very good !
 

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

So we have now 'built' our interface, just the menus and coding to do.

Just to refresh this is where we should be, your interface should look something like fig 23 below:
 

Attachments

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

First we need to open Xcode and double click on our runDaily.scpt, then add the following code into it and save. (fig 24)


on «event coVScliI» theObject
tell window of theObject
tell application "Finder"
say "hello Ric"
end tell
end tell
end «event coVScliI»

Now do a 'run and build' and test the Run Daily Button, does it say hello Ric, if it does we are in business. This is just showing you that our button works and is now linked into the program...just check you have the sound turned up !

Project in its current state is posted below.

We are now happy that we are connecting the dots as it were...

The button works !

We have only used the 'say hello Ric' so that we can instantly tell that the button is connected up and fully functional !

We will now strip out the 'speech code' and enter the real script...
 

Attachments

Danster

New Member
Joined
Feb 12, 2005
Messages
267
Reaction score
8
Re: Applescript Studio

Hi

I would like to carry on with my converter and having copied the GUI you made (for practice) and have an idea that I would like to use in it.

Seeing as the conversion rates are ever changing, I would like my AS to automatically update itself from a website such as xe.com

What I mean is that AS selects the specific text from the website (the USD conversion) and rewrites the old rate with the new one such every week.

As I've never done this before I've no idea how it can be done but was just wondering if it was possible as I think it's a good way of practicing.
 

Attachments

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

No problem ! I'll finish up this "Maintenance App" tonight then we'll get started on your Temp Converter App !

Regards

Ric
 

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

Now back to the code,

strip out the speach text, and change the daily script to be:

Code:
on «event coVScliI» theObject
	tell window of theObject
		tell application "Terminal"
			do script "sudo periodic daily"
		end tell
	end tell
end «event coVScliI»
then save build and run it...

...now you can see, that when the Run Daily button is clicked, the Application 'Terminal is launched and the code...sudo periodic daily is entered...

at this point it will ask for your administrators password, this is because we have to 'run' perodic as a Super User or Root User...

I have 'purposely' made this a bit messy so that you can see what's happening...

in real life we would not enter the script above...

we would use:

Code:
on «event coVScliI» theObject
	tell window of theObject
		
			do shell script "sudo periodic daily"

		
	end tell
end «event coVScliI»
or we could use

Code:
on «event coVScliI» theObject
	tell window of theObject
		
			do shell script "periodic daily" with administrator privileges

		
	end tell
end «event coVScliI»
Try one after the other, and build and run.

I am going to use the second script as I prefer the way that interacts with the user.

Before running the new script's open the "Activity Monitor" in the Utiliites folder from within the Apps folder, so that you can see that something is happening when you click the button.
 

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

So now we need to enter in the code for the Run Weekly, Run Monthly and for the Run all Script. So back to Xcode and modify the AppleScripts.

They are as follows:

Run Weekly:

Code:
on «event coVScliI» theObject
	tell window of theObject
		
		do shell script "periodic weekly" with administrator privileges
		
		
	end tell
end «event coVScliI»
Run Monthly:

Code:
on «event coVScliI» theObject
	tell window of theObject
		
		do shell script "periodic monthly" with administrator privileges
		
		
	end tell
end «event coVScliI»
Run All:

Code:
on «event coVScliI» theObject
	tell window of theObject
		
		do shell script "periodic daily weekly monthly" with administrator privileges
		
		
	end tell
end «event coVScliI»

nice and easy !!
 
Ad

Advertisements

Ric

New Member
Joined
May 14, 2004
Messages
4,260
Reaction score
4
Re: Applescript Studio

Now build and run... and test all the buttons, if you watch the Activity Monitor, you will be able to see it working !

Latest build...project below.
 

Attachments


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