Search code examples
applescriptmountfinder

Copy mounted folders to local folder


We have a samba share from where I'd like to copy folders with an applescript. This is what I already have (the mounting works):

mount volume "smb://samba.com/e_18_data11$"
delay 3

set sourcefolder to ("smb://samba.com/e_18_data11$/e_18_data11$/folder1/folder2" as POSIX file)
set localfolder to ("/Users/username/Dropbox/Test" as POSIX file)

tell application "Finder" to duplicate sourcefolder to localfolder

This gives me still this error:

the routine can not edit objects of this class." number -10010

I tried and combined many solutions already on SO, e.g. this solution

– OS X 10.9


Solution

  • It's probably the sourcefolder specification that is wrong. I think you can just use the volume name instead of "smb://".

    set sourcefolder to ("/Volumes/7samba.com/e_18_data11$/e_18_data11$/folder1/folder2" as POSIX file)
    

    (if the mounted volume is named "7samba.com")


    Tip: drag the actual sourcefolder from Finder into your AppleScript. It should paste the path into the script. Use that path for sourcefolder.


    More:

    The Error your getting is:

    Mac OS error -10010 (telBadHTypeErr): bad hook type specified
    

    I tested it (with two local folders) to see if the script would work. It did work and duplicated the folder.

    You can (or should anyway) wrap critical code into a try block, like this:

        try
    
            duplicate sourcefolder to localfolder
    
        on error the error_message number the error_number
            display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
        end try
    

    This way you can check and react to errors.

    Addition:

    May be you can check for existence like this:

    tell application "Finder"
        set aBoolean1 to get (exists sourcefolder)
        set aBoolean2 to get (exists localfolder)
    end tell
    
    log aBoolean1
    log aBoolean2
    

    Both bool's must be YES