Introduction to AppleScript line

This tutorial will show you some basic in using AppleScript and REALbasic. The AppleScript is offering users an intelligent mechanism to control applications, and access and modify information and documents. We can use it in REALbasic for example to play music in iTunes, display contact from Address Book etc.

AppleScript Terminology

How can we know that for example iTunes offers a option to play and pause the music using AppleScript? The answer is quite easy. To get the list of iTunes options available for AppleScript we must only drag and drop iTunes app into AppleScript Editor icon displayed in Dock. The Terminology window will open like on the screen below.

Introduction to AppleScript for REALbasic

AppleScript example – iTunes play

Open AppleScript Editor and write this code into this editor. Next Compile it and click on Run button. When everything will go good your iTunes should lunch and play the music. If it’s already running then it will only play the music.

1
2
3
tell application "iTunes"
	play
end tell

AppleScript multiline command example

We can also add more commands to our AppleScript file, like in this example. This code will return the number of files available in “Application” folder.

1
2
3
4
5
6
7
tell application "Finder"
    if folder "Applications" of startup disk exists then
        return count files in folder "Applications" of startup disk
    else
        return 0
    end if
end tell

Add parameters to AppleScript

There is also a option to add some parameters in “on run” event. This example runs the Growl Notification System and pass the growlDescription and growlTitle to GrowlHelperApp. If you like to know how to interact this kind of AppleScript with REALbasic then go to my tutorial Growl notification system for REALbasic.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
on run {growlDescription, growlTitle}
 
	tell application "GrowlHelperApp"
 
		set the allNotificationsList to ¬
			{"Notification"}
 
 
		set the enabledNotificationsList to ¬
			{"Notification"}
 
 
		register as application ¬
			"Our application name" all notifications allNotificationsList ¬
			default notifications enabledNotificationsList ¬
			icon of application "Safari"
		notify with name ¬
			"Notification" title ¬
			growlTitle description ¬
			growlDescription application name "Our application name"
 
	end tell
 
end run

Author: Jakub Pawlak

I'm interested in all. Currently working on the development of TUTSPOLIS and I hope that in near feature the project will be successful.

2 Responses to “Introduction to AppleScript”

  1. Tom Waits says:

    Thats original! :)

Leave a Reply

Copyrights (c) TUTSPOLIS | Powered by Wordpress MU | Inspired at Elegant Themes designed by qbap (HTML5 & CSS3)