Someone on one of the Facebook FileMaker Group pages recently asked for a simple method, using AppleScript of creating a folder on the Desktop. FileMaker Pro can generate a variety of file formats, including Text, PDF and Excel, and it is possible to script the names of these files. It is also possible to script saving files to specific locations on your hard drive. Unfortunately FileMaker lacks the ability to create folders without the use of plugins. AppleScript on the Macintosh gives FileMaker this ability. I found the basics of this script on Stack Overflow. I thought I would flesh it out into a demo file, put in some error checking and share it here.
Create a Folder
Enter a Folder Name and then click one of the buttons to create a folder in that location.
Folder Created on the Desktop
Button Setup
Each button runs the same script but use a different Script Parameter to determine where the Folder will be created.
Other Possible Locations
The options are: Desktop, Dropbox, Google Drive and Documents. It is possible to use other locations, basically any location starting from the User level, such as Pictures, Music, Sites etc. It is also possible to hard code the path into the script and skip the need for a Script Parameter on the button.
FileMaker Script
Edit Script “Create a Folder with Applescript”
The script is pretty simple.
- a check to see if this is a Macintosh capable of running AppleScript.
- setup four variables
a) $FolderName – from a global field.
b) $UserName – this is the Macintosh System User Name as opposed to FileMaker Account Name.
c) $ScriptParam – where to place the folder – Desktop, Documents, Google Drive, Dropbox
d) $Path – a calculated version of the Path to the folder. This is used in the AppleScript to check to see if the folder already exists. - Check to see if the Folder Name has been filled in.
- Run the Calculated AppleScript using the four variables.
Adapting to your solution
You should be able to copy and paste this script into any FileMaker 11, 12 or 13 database and have it run correctly, once you set up the source field for your Folder. It is not necessary to use a global field, it could be any regular field.
Modify the $FolderName variable to something appropriate in your own database.
The AppleScript Calculation
This looks a little complicated, but all that is really happening is that the variables in the AppleScript are being replaced with values from FileMaker. Quotations marks are being escaped, because they confuse FileMaker, but AppleScript requires them. Finally paragraph returns are inserted so AppleScript can read the lines correctly.
The script sets up some parameters, including the Folder Name and some parameters for the error Notification, if the folder already exists.
Here is the Calculated AppleScript:
set folder_name to "•••My Folder Name" set notificationTitle to the "The Folder '" & folder_name & "' Already Exists" set notificationSubTitle to "This script has already been run." set notificationMessage to "No further action is necessary at this time." tell application "Finder" activate --test to see if a folder exists. if exists folder ":Macintosh SSD:Users:yourusername:Google Drive:•••My Folder Name" then display notification notificationMessage with title notificationTitle subtitle Title sound name "Chime" delay 1 else -- if no folder exists, then create one. make new folder at folder "Google Drive" of folder "douglasalder" of folder "Users" of startup disk with properties {name:folder_name} end if end tell
That’s it. Hope this is useful.
2015-05-21 Update: Added an AppleScript/FileMaker script to create sub-folders to the demo file. Simplified the AppleScript with a ‘Try/End Try’, instead of using the ‘If/Else’ to test to see if the folder exists.
The download is not working today, Douglas.
I thought that FileMaker 14 had something new concerning handling folder …
Any confirmation ?
Have a sweet day.
Thanks Didier. You were right, it was broken. Fixed now. Direct link is here. I think what you are referring to in FileMaker Pro 14 is the new Get(Directory) script step. There is a video on the topic by Soliant here.
Thanks Douglas.
>https://s3.amazonaws.com/hbase-files/HB_Window_Management_Test_To_See_If_A_Window_Is_Open.fmp12.
>Access Denied
The last character in your link (a point) should be removed.
In the post above, the link doesn’t shows up.
Try it again.
The link in the post is Perfect now.
this is (almost 😉 ) exactly what i’ve been looking for… thank you!
Is there a way to add subfolders within the named folder too?
Hi Dom, Please see the revised demo for a second script that does what you want.
very kind! incredibly swift…
however… I’m getting this error:
Finder got an error: Can’t get folder “” of folder “dommoir” of folder “Users” of startup disk.
when i run the script in my solution… any ideas?
Make sure that your list has no double spaces in it. Activate the debugging steps in the script. Copy the generated AppleScript from the global field into Script Editor and see where the problem lies.
thx douglas… I’ll check it tomorrow… very late in the UK now
grazie mille
Hi Douglas,
Managed to sort the issue… i wasn’t specifying the variable “Desktop”… silly me 🙂