Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Aouttier

macrumors member
Original poster
Mar 3, 2016
42
0
Belgium
Hello,

I’ve just switched from Windows to mac (and I’m happy with my decission!).
Now, I’m trying to write an apple script to make a folder on my external hard disk (NAS). My hard disk is mounted, I can see the following in Finder. The disk is called ‘Diskstation’ (As you can see, I’m dutch speaking)

724BA204-21AF-435C-86C0-1AC8AB7E9665_zpskmv9zll3.png~original


I’ve looked on the internet, I’ve found a lot of solutions (and tried them), but none seems to work.
The last thing I tried is:

Code:
set DiskName to "DiskStation"
set FolderName to "Heron"
tell application "Finder"
    set DoelFolder to folder FolderName of disk DiskName
    make new folder at DoelFolder with properties {name:"test"}
end tell

Can anyone say me what I’m doing wrong and give me an advice on how to do it?

Thanks in advance
 
Last edited:
Hi,

Welcome to the world of the Mac!

I'm assuming that a folder called "Heron" already exists on the disk DiskStation, and you want to make a new folder inside the "Heron" folder. If so, I'd do it something like this:

Code:
tell application "Finder"
    make new folder in alias "DiskStation:Heron:" with properties {name:"test"}
end tell

You weren't too far wrong and the AppleScript dictionaries can be a bit confusing at times. Personally, I think the Finder's is especially bad. You'll get used to it!
 
I still doesn't work. I even can't compile it.

Schermafbeelding%202016-03-03%20om%2020.17.03_zpstcetuahy.png~original


It says that he can't find 'DiskStation: Heron'. When I change the 'in' in 'at', it's compiling. But, when I execute the script, he can't find the folder.

What is still wrong?
 
It didn't work either...

I tried a bit further, also some surfing. I tried

Code:
set loc to "DiskStation:Heron:"
tell application "Finder"
    make new folder at folder loc with properties {name:"test"}
end tell

But now I get the fault -1728 (The referenced object doesn’t exist. This is a run-time resolution error, such as when attempting to reference a third object when only two objects exist.) I would say that the disk isn't mounted, but I can make a folder in the folder 'Heron' on the Diskstation manually. Thus, that seems not to be the problem...
 
Hmmm.

Can you try this...

Code:
set theFolder to choose folder
set thePath to (theFolder as alias)
display dialog thePath as text

...select your folder where you want to make your folder when prompted, and let me know what the dialog says.
 
What are the names of the shares on the Diskstation?

I have the following partitions/shares: fotografie, multimedia, muziek & opslag.

So if I want to make a folder called test on my Nas on the share opslag the code must be something like:

Code:
tell application "Finder"
    make new folder of alias "opslag:" with properties {name:"test"}
end tell
Schermafbeelding 2016-03-07 om 15.58.28.png


Succes
 
Last edited:
Hmmm.

Can you try this...

Code:
set theFolder to choose folder
set thePath to (theFolder as alias)
display dialog thePath as text

...select your folder where you want to make your folder when prompted, and let me know what the dialog says.


It works when I change the code a little bit (without the alias)

Schermafbeelding%202016-03-08%20om%2021.53.30_zps2ervdft7.png~original
 
It's driving me crazy...

When, I execute your code, I got the following error:

Schermafbeelding%202016-03-09%20om%2020.18.39_zpsgh51vksb.png~original

(translated: the script isn't found)

I then tought that the drive wasn't corrected mounted. So, I expanded the script that it also mounted the volume:
Code:
    if exists disk "192.168.1.107" then
        display dialog "volume is mounted"
    else
        display dialog "volume isn't found"
        mount volume "smb://admin:xxxxxx@192.168.1.107/Heron"
    end if
end tell
set theFolder to "192.168.1.107:Heron"
set thePath to (theFolder as alias)
display dialog thePath as text
tell application "Finder"
    make new folder at theFolder with properties {name:"test"}
end tell

When, I unmount the disk, and then execute the script, I see that the disk is mounted, and then I got the following error:
Schermafbeelding%202016-03-09%20om%2020.42.42_zpsxvjwcrgp.png~original

I can't figure out what is wrong


Thank you for helping me
 
When a drive is mounted it is part of the file system. If you go in Finder to the folder /Volumes (Finder -> Ga -> Ga naar map... en geef daar in /Volumes).

In Volumes you will see a volume called Heron when this partition is mounted. If this is the case then you can use the following code to make the folder on your NAS:

Code:
tell application "Finder"
    make new folder of alias "Heron:" with properties {name:"test"}
end tell

Applescript "knows" that the drives (internal drives, network drives, USB drives etc.) are accessible through the /Volumes folder, so you don't have to mention that in the above code, only the name "Heron:" is enough.

I think you can't access network drives directly through the IP number (like Windows), they first must be mounted to access them. I'm not 100% sure about this.
 
Last edited:
It's driving me crazy...

(…)

I then tought that the drive wasn't corrected mounted. So, I expanded the script that it also mounted the volume:
Code:
if exists disk "192.168.1.107" then
        display dialog "volume is mounted"
    else
        display dialog "volume isn't found"
        mount volume "smb://admin:xxxxxx@192.168.1.107/Heron"
    end if
end tell
set theFolder to "192.168.1.107:Heron"
set thePath to (theFolder as alias)
display dialog thePath as text
tell application "Finder"
    make new folder at theFolder with properties {name:"test"}
end tell

When, I unmount the disk, and then execute the script, I see that the disk is mounted, and then I got the following error:
Schermafbeelding%202016-03-09%20om%2020.42.42_zpsxvjwcrgp.png~original

I can't figure out what is wrong


Thank you for helping me


(FYI, error -43 means "file not found")

I think your problem may be a missing colon after "Heron" when you set theFolder in your script.
I've just tried this script successfully at home:

tell application "Finder"
set newFolder to make new folder at alias "Archives:" with properties {name:"Test folder"}
end tell

where "Archives" is the name of a remote volume on my NAS on which I have the necessary rights to write.
In my case, DiskStation413 is the name of the server (NAS), and "Archives" is the name of one of the volumes shared by this server. By the way I access this server through AFP (not SMB).

So, in your case, if the volume "Heron" on your "DiskStation" server (NAS) is already mounted, and provided that you have writing rights to this folder, this script should work:

tell application "Finder"
set newFolder to make new folder at alias "Heron:" with properties {name:"test"}
end tell

If I need to mount the volume first, I can do this:
mount volume "afp://myUsername:myPassword@DiskStation413._afpovertcp._tcp.local/Archives"
tell application "Finder"
set newFolder to make new folder at alias "Archives:" with properties {name:"test"}
end tell

I tested it and it works perfectly. I don't know why the more verbose (and more AppleScript style) syntax of mount volume (that is mount volume "Archives" on server "DiskStation413" as user name "xxxx" with password "xxxxxxxx") did not work though. :(
Anyway, this should work for you too, with the names of your volume and server:

mount volume "afp://yourUsername:yourPassword@DiskStation._afpovertcp._tcp.local/Heron"
tell application "Finder"
set newFolder to make new folder at alias "Heron:" with properties {name:"test"}
end tell

Or something similar with SMB instead of AFP if you did not turn on AFP on your NAS (but as you already succeeded in mounting this volume, you should be able to do it as you did it before; if you are interested to know where this ._afpovertcp._tcp.local part came from, just do a "Get info" (command-I) on your Heron volume in the Finder).

Happy coding!




 
NOw, it's working ... with al your tips and a lot of trying.

I don't really know why it is working now, but I'm happy that it's working!

Thanks a lot!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.