We have a customer who logs into a Samba network and wants updated files from his laptop to be copied to the network volume.
Is there a way to use AppleScript so that when he logs in it checks network connectivity and thus subsequently drive mappings and then copy across all the updated files that he’s worked on to the network?
set shareName to "SMB_Disk"
set localFolder to "path:to:local:folder:"
set remoteFolder to "path:to:server:folder:"
tell application "Finder"
-- check if the server is mounted
if (exists volume shareName) = false then
-- not mounted, so mount it
open "smb://username:password@server/SMB_Disk"
end if
-- now copy the files
duplicate every file of folder localFolder to folder remoteFolder with replacing
end tell
The easiest way to do this is to add a property to your script that tracks the last run time and use that as a comparison to find new files:
property lastRun: date "Thursday, January 1, 2004 12:00:00 AM" -- some arbitrary date
set shareName to "SMB_Disk"
set localFolder to "path:to:local:folder:"
set remoteFolder to "path:to:server:folder:"
tell application "Finder"
-- check if the server is mounted
if (exists volume shareName) = false then
-- not mounted, so mount it
open "smb://username:password@server/SMB_Disk"
end if
-- now copy the files, note the 'whose clause' to restrict the files
duplicate (every file of folder localFolder whose modification date is greater than lastRun) to folder remoteFolder with replacing
end tell
-- update the lastRun property
set lastRun to (get current date)
The property will automatically be saved in the script and used in subsequent runs of the script.