noob: call an applescript from another applescript

Hey all,

New here :wink:
I searched the forums, but couldn’t find what I need.
Please move if this isn’t the right forum, thanks. :slight_smile:

I’m trying out applescript by making a small backup thingy.
This script backs up files to my Documents folder in an organized way.
Next I’m making a seperate script to copy that backup folder from Documents to my iPod when I connect it.
I would like to call the backup script before copying to my iPod, in order to get the latest files.
I might change the backup script to backup more or different files over time.

When I execute the script to copy my backup to my iPod, I want it to execute the backup script first.
So I figure need to do something like:
do applescript “path:to:backup:script.scpt”

Can you please help my with the syntax?

Hope it is clear.
Thanks a lot :slight_smile:


See Standard Additions’ ‘run script’ command. Example:

run script alias "path:to:backup:script.scpt"

Thanks for the quick reply, I can’t get it to work though:
Finder got an error: Can’t make some data into the expected type…

The backup script just deletes and copies some files and empties the trash, BTW

And what does alias mean in the line you gave me?

Thanks again :slight_smile:

Sounds like a bug in your backup script which I assume uses Finder to perform its various tasks.

The AppleScript language defines a number of built-in types for identifying both existing and new files, folders and disks within your Mac’s filesystem. (Not to be confused with any filesystem-related classes and objects defined in individual scriptable applications such as Finder and System Events.) alias “some mac path” defines an object of type alias, used to identify an existing file, folder or disk.

Man you’re fast hhas, quiet day at the office? :wink:

I changed things around a bit, so I’ll only need 1 script.
It tries to zip the folder to the iPod if attached.
Nice to know how to run another script for future work though :slight_smile:

I know a bit of Perl and decided that I would be able to use Applescript without too much specific education.
I would greatly appreciate if you could look at it to see if I got the hang of things, or need to get a tutorial.
It works, but I’m not overly sure if it’s the proper way to handle things.

tell application "Finder"
	-- list of files to back up
	-- backup Safari bookmarks & form values
	duplicate file "Library:Safari:Bookmarks.plist" of home to folder "Documents:Backup:Safari" of home with replacing
	duplicate file "Library:Safari:Form Values" of home to folder "Documents:Backup:Safari" of home with replacing
	-- backup iTunes library files
	duplicate file "Music:iTunes:iTunes 4 Music Library" of home to folder "Documents:Backup:iTunes" of home with replacing
	duplicate file "Music:iTunes:iTunes Music Library.xml" of home to folder "Documents:Backup:iTunes" of home with replacing
	-- delete older Mail backup
	if folder "Documents:Backup:Mail" of home exists then
		delete folder "Documents:Backup:Mail" of home
	end if
	-- backup mailboxes
	duplicate folder "Library:Mail" of home to folder "Documents:Backup" of home
	-- check if iPod is connected	
	if file "" of disk "Toto" exists then
		delete file "" of disk "Toto"
		empty trash
	end if
	-- zip to iPod
		do shell script ("/usr/bin/ditto -c -k -rsrc --keepParent ~/Documents/Backup /Volumes/Toto/")
	end try
end tell

BTW Toto is my iPod

You seem to have the basic principles of application scripting pegged just fine. Good luck with it.



BTW for other people viewing this script:
note that it will empty the trash, you might not want to do that if you keep stuff in the trash, which I never understood, but anyway