BlogFileMaker

Creating OS Folders and Subfolders with FileMaker

By September 28, 2015 September 5th, 2019 17 Comments

Folder iconIt is very common to generate reoccurring reports in FileMaker that get saved to the user’s computer. Perhaps you would like to organize these reports by day or type. OS level folders and subfolders are a great way to do this. This demo file attached shows you how to create a folder and a subfolder on your user’s computer using FileMaker.

Here’s an overview on how the sample file works:

  • The layout asks you to enter a folder name and a location for the folder (either desktop or documents folder). If the location is the same every time, you can hard code the location in your script.
  • The script confirms that none of these values are empty.
  • The subfolder name is calculated based on the date and time. This ensures that no two subfolders will have the same name, which would cause an error.
  • Check if we are on Windows or Mac.
    • If we are Windows, we run a Send Event script step that makes the directory specified.
    • If we are on Mac, perform applescript to create the main folder, and then perform applescript again to create the subfolder.
  • Let the user know if there was an error or if everything was successful.

You can download the demo file here: CreateFolders.fmp12

Makah Encarnacao

Makah Encarnacao

Makah is a Technical Project Lead that hails from Albuquerque, NM. She joined Soliant a few months after graduating from UCLA in 2007, and must like it a lot because she’s still here! She is certified in FileMaker 9, 10, 11, 12, 13, 14, 15, 16 and 17, and placed 4th in the 2015 FileMaker DevCon Developer Cup. She was a speaker at the 2016 and 2018 FileMaker Conference. When she is not coding, she is enjoying life with her family that recently increased by 1.

17 Comments

  • Avatar Jim Medema says:

    Makah,

    Thanks for the sample file – clear, simple, verrry useful! Especially appreciate the platform-independent element given that my knowledge and preferences are for Macs and my PC knowledge is more limited.

    Jim

  • Avatar Kristy Lapidus says:

    Good idea, Thanks for sharing!

  • Nice and clear, a good foundation to create a recursive version that handles any valid path, even when folders are missing somewhere along that path.

  • Avatar tom langton says:

    Nice clean Applescript. I’ve been doing similar scripts through FM to create job folders and subfolders on a production server. FM then builds the directories in the correct location, based on client name, and will open the folder if it already exists.
    When it’s time to archive, FM knows where the folders are, since it calculated the paths where they are created, and then can grab all the file names and specs in those folders before archiving.

  • Avatar David says:

    Hello. Very cool setup! So I’m a novice at this, and I’m trying to get the script to create a folder in a specific place on my Windows computer (not on the Desktop or in the Documents directory). For example, I’d like the script to create the FolderName in C:\Users\Username\Music\. Could you possibly help me out?

    • Avatar Makah Encarnacao says:

      Hi David. I was able to create the new folder in my music folder by doing the following in the sample file:

      • Set the setting on the layout to be documents path, and press the Create Folder button while your script debugger is open
      • I stepped through the script with my script debugger until I got to script step 15, where it sets the $path
      • I opened the data viewer and copied the path, for me it was “/C:/Users/mencarnacao/Documents/”
      • I duplicated the script “Create Folder” and I updated the $path calculation in step 15 to be “/C:/Users/mencarnacao/Music/”.
      • I hard coded it just to test, but you could do a get( documentspath) and then do a substitute with “Documents” and “Music” so it works on multiple machines.
      • I then ran the duplicate script and it worked fine.

      If that doesn’t work you may have a permissions issue on your Music folder. Hope that helps! Good luck!

    • Avatar David says:

      Hey, thanks so much for the reply! I’ll give it a whirl!

  • Avatar dsjprinting says:

    I am trying to implement a feature in the filemaker database I am creating for my work that uses your technique of making a folder using AppleScript in Filemaker. i am running into some issues since the folder I want to create is on our Apple Server and not on the local machine. The server drive (share) is named “Art_Department”. How would I modify the applescript to create a folder on the server instead of the local desktop or document folder. Any help is greatly appreciated.

  • Avatar Angelo says:

    Hi David, I would like to create something similar as Makah (Jan 11, 2016). Unfortunately your solution doesn not work for me because: 1. I don’t have Filemaker Advanced, so no debugger and 2. I use Mac. The script uses ‘desktop’ and ‘documents’ near the end of the script. I cannot find how to change these to a new field (PATH), where the new path could be written into. Any help is welcome!

  • Avatar Frank says:

    Any chance of uploading a Demo File that allows us to define the path in a field? I just can’t seem to get it. Running on MAC

    • Avatar Makah Encarnacao says:

      Hi Frank, for the OSX version, the applescript is creating the path, not filemaker. I’m using applescript’s “path to desktop folder” function or “path to documents folder” function to get the path, which is set as a variable in the applescript defined as “theOutputFolderPath”. I’m not an applescript expert, so I’m not sure how to construct a path that’s not to the desktop or the documents folder; I would have to look it up. Let me know if you don’t find a solution and I will do some digging.

  • Avatar Tony White says:

    Very nice blog post and demo file…

    Here is one way to discover a folder path…

    [begin excerpt]
    set a_folder_path_HFS to choose folder — or choose file
    set a_folder_path_HFS to a_folder_path_HFS as string
    set the clipboard to a_folder_path_HFS

    display dialog “the path to the folder is on the clipboard.” buttons “OK” giving up after 3 — seconds
    [end excerpt]

    How to set color/label index and type coercion here:
    https://community.filemaker.com/message/644537?et=watches.email.thread#644537

    Thanks.

    Tony

  • Avatar Dom Moir says:

    Hi there… The demo file seems to be completely empty… Any chance you can mail me a working version?

    • Avatar Makah Encarnacao says:

      Hi Dom,
      Try saving the file as a .zip file when you download it. Then unzip the file and it should work. Apologizes for the confusion.

      Makah

  • Avatar Tyler Martin says:

    This is a great tool, is there a way to modify the applescript and windows script to go to a file path, instead of just the desktop or documents? I’d like to create new folders within our Dropbox, which is always in a users home directory on Mac, but on Windows it can vary depending on OS version.

    • Avatar Makah Encarnacao says:

      Hi Tyler, thanks for the feedback. I haven’t actually tried it myself, but if you look at Tony White’s comment above, he does provide some tips on how to set the path to something other than documents/desktop for AppleScript. According to this article about applescript, (https://discussions.apple.com/thread/3809986), it looks like you can change the path to “Mac HD:Users::Dropbox” where is the computer’s user name.

      For Windows, see my comment above in reply to David where I help him with the music folder. If the path varies, you can try using the Get Directory () script step to have the user select the path. This script step also has a “Allow Create Folders” option so they can create new folders from this dialog as well. Hope that helps!

Leave a Reply