I have no specific explanation for your symptoms, but a few observations:
- Your script as written doesn't work on my OS X 10.8 and 10.9 machines - find a streamlined version below. What version are you using?
- Given the nature of your script there's no strict reason to save it as an application - you could instead save it to a regular
*.scpt
file and tell Lingon to execute the following (note the need to use full paths both forosascript
and your*.scpt
file):
/usr/bin/osascript /path/to/your/script.scpt
The problems I encountered on OS X 10.8 and 10.9:
- The
mount volume
command neither directly returns a value nor sets the globalresult
variable - my streamlined version simply tries instead to access the share as a mounted disk. - The variable name
server
resulted in strange errors; changing the name made them go away.
Streamlined version:
# Mount the share.
# Note that at least on OS X 10.8 and 10.9 this command:
# - is a no-op if the share is already mounted
# - in either case has NO return value and does NOT set the
# global `result` variable.
# The share will be mounted as "disk" /Volumes/{shareName} (POSIX) /
# {shareName}: (HFS)
# Note that the `mount volume` is defined in the Standard Additions dictionary,
# not the Finder's.
set destShareName to "sharename"
mount volume "smb://<username>:<password>@server.domain.com/" & destShareName
# Getting here without error means that the share was just mounted
# or was previously mounted.
tell application "Finder"
# Get a reference to the mounted share.
# !! It seems that at least on OSX 10.9 it can take a few seconds
# !! before a just-mounted
# !! share becomes accessible.
# !! We try for a while, but eventually give up.
set numTries to 5 # How many seconds (at least) to keep trying.
set numTry to 1
repeat
try
set destShare to disk destShareName
exit repeat
on error errMsg number errNo
set numTry to numTry + 1
if numTry > numTries then error errMsg & " - giving up after " & numTries & "+ seconds." number errNo
delay 1 # Sleep for 1 second, then try again.
end try
end repeat
# Define the SOURCE *HFS PATHS*.
set sourceFolderPaths to {"Macintosh HD:<location to share1>", "Macintosh HD:<location to share2>", "Macintosh HD:<location to share3>", "Macintosh HD:<location to share4>"}
# Define the corresponding DESTINATION *FOLDER NAMES*
set destFolderNames to {"share1", "share2", "share3", "share4"}
# Process all folders.
repeat with i from 1 to length of sourceFolderPaths
set sourceFolderPath to item i of sourceFolderPaths
set destFolderName to item i of destFolderNames
# Get a reference to the destination folder or create it, if it doesn't yet exist.
try
set destFolder to folder destFolderName of destShare
on error # folder access failed -> assume it must be created
set destFolder to make new folder with properties {name:destFolderName} at destShare
end try
# Copy the files. This will overwrite all files.
duplicate items of folder sourceFolderPath to destFolder with replacing
end repeat
# Unmount the share.
eject destShare
end tell