Tag Archives: Applescript

Chronosync backup when drive plugged in with applescript

Firstly excuse the extremely uncreative title of this post but I have been working all day and my creativity levels are a little on the uncreative side at this stage of the day.
At the studios we have couple of different backup systems running to DLT and LTO tapes plus some offsite drives that we use for disaster recovery. After struggling with massive issues with the latest version of retrospect for mac and the horrible support we decided to move to Chronosync which has been fantastic.
One thing that we wanted to do was automatically run a backup when we connected a particular offsite backup drive. I managed to get this to work by running an applescript in automater whenever a new drive was added using folder actions.

When new drives are added to OSX they are mounted in the /Volumes folder which you can’t normally access in finder. To get around this you can create a symlink in the terminal by typing:

ln -s /Volumes/ ~/vol-link

this will create a link named “vol-link” in your home folder that points to the Volumes folder.

Then open automater in the applications folder and chose “folder action” from the start up screen

On the top you can choose the folder that will perform an action if a file or folder is added to it.
In here choose your vol-link.

Drag across the “Run AppleScript” action form the left and then add the AppleScript code from below

Note that you will have to change the volume names and path of your Chronosync container document and you can modify this script to work with more drives or less.

Save your workflow and that’s it.

We also have our backups stored in an encrypted disk image so have set the last document in the container to eject the image when it’s finished. The script then ejects the drive

Any questions or comments let me know

set VolumeName1 to "OffsiteBackUP1"
set VolumeName2 to "OffsiteBackUP2"

if volumeMounted(VolumeName1) = 1 then
	try
		tell application "ChronoSync"
			activate
			
			open alias "HD RAID:Users:serverhomedir:Documents:Offsite Backup 2.csyn"
			
			tell document 1 to Synchronize
			
			--hold on 'till the sync is complete
			
			repeat while syncStatus of document 1 is not 0
			end repeat
			
			tell document 1 to save
			tell document 1 to close
			
			
			
			
		end tell
	end try
	
	delay (5)
	
	tell application "Finder"
		activate
		eject disk VolumeName1
		
	end tell
	
	
else
	
	if volumeMounted(VolumeName2) = 1 then
		
		
		
		try
			tell application "ChronoSync"
				activate
				
				open alias "HD RAID:Users:serverhomedir:Documents:Chronosync Offsite Scripts:Offsite Backups.csyn"
				
				tell document 1 to Synchronize
				
				--hold on 'till the sync is complete
				repeat while syncStatus of document 1 is not 0
				end repeat
				
				tell document 1 to save
				tell document 1 to close
				
				
				
				
			end tell
		end try
		
		delay (5)
		
		tell application "Finder"
			activate
			eject disk "VolumeName2"
			
		end tell
		
	end if
	
end if

on volumeMounted(VolumeName)
	tell application "Finder"
		if (exists disk VolumeName) then
			return 1
		else
			return 0
		end if
	end tell
end volumeMounted

VNC Connect Applescript

At the studio we run a Mac based network with multiple servers and clients. With remote desktop enabled on the Macs or a VNC server (such as Tight VNC) on Windows it’s easy to view and control the screens of remote systems. Which is pretty handy when most of your systems are located in a distant machine room and don’t want to get off your chair.
While it’s pretty easy to select the computer in the finder and press screen share, I decided to write an Applescript to streamline the process of frequently connecting to same remote systems and thought I would share it in case anyone finds it useful.

The remote systems will need to have a static IP address and this script will only work with OSX 10.5 and up.
To customise the script all you need to do is change the values in the lists and ensure that the name and address values keep their relative position in the list. You can also add more than three systems by just adding to lists.

 

(* VNC Connect script v1 www.sandymilne.com *)

on get_pos(aCompterName, aList)
	repeat with theItem from 1 to the count of aList
		if item theItem of aList is aCompterName then return theItem
	end repeat
	return 0
end get_pos

(* Set computer address and Names *)

set computerNameList to {"Server", "Windoze", "iMac 1"}
set computerAddressList to {"10.0.0.8", "10.0.0.6", "192.168.1.22"}


set selectedHostName to choose from list computerNameList with prompt "Select a host:"

if selectedHostName is not equal to false then
	set connectwith to item (get_pos((selectedHostName as string), computerNameList)) of the computerAddressList
	
	do shell script "open -W vnc://" & connectwith
end if



 

You can download the script here:
VNC Connect.zip