July 26, 201015 yr Hi everyone, I'm looking for a way to create thousands of folders in Finder, which will be named after an ID Field in Filemaker. I have a contacts database,with a unique ID, and i'd like to create one folder for each contact to store in the emails and other documents. Every contact folder would have the same structure : 000001 (root folder, named after contact_id field in filemaker) -->2009 -->2010 -->2011 After the first creation of folders, the script would create a folder everytime a contact is created, and therefore , delete it everytime the contact is not found. Is there a Filemaker Script? or Applescript? Many many thanks in advance for your help! Edited July 26, 201015 yr by Guest
July 26, 201015 yr Applescript can do this, though it is obviously platform specific. I've also seen it done with Troi File and other similar plug-ins. I'd also look into using SuperContainer.
July 26, 201015 yr Author Thanks Vaughan, i'd rather do this using applescript, my platform is mac os 10.6, using Filemaker Pro Advanced 11 and Filemaker Server 11 on a Snow Leopard Server. Could you help me set this up?
July 26, 201015 yr The "delete" folder if client does not exist would be an entirely different operation. AppleScript would be looping (via repeat) thru the set of folders, then looking for its record in FileMaker. The "create" folders would be the opposite, looping thru the FileMaker records and creating folders. It would use the mkdir shell script command. It is very fast and pretty flexible. The ID field should be on the layout, as that's the simplest way for AppleScript to see it. The code below is the AppleScript for one Contact, which you'd put into Perform AppleScript step, as native. You would run this within a Loop in FileMaker, letting FileMaker step thru the records. The mkdir command is smart, it will not overwrite an existing folder. The below creates the folder structure on your Desktop, for simplicity. You can then move it wherever. If you have a known location, then you'd use that. I'm assuming that there is no space in the IDs, which makes it easier. If any of the paths has spaces, then you must quote it (and only it; you cannot just quote the whole command argument). But luckily yours has no spaces. --tell application "FileMaker Pro Advanced" set fm_id to cell "ContactID" of current record --end tell set desktopPath to POSIX path of (path to desktop) set mkdirStr to "mkdir -p " & desktopPath & fm_id & "/{2009,2010,2011}/" do shell script mkdirStr P.S. --tell application "FileMaker Pro Advanced" is commented out. It is not needed/wanted in FileMaker itself, but is needed (uncommented) to compile or run the script in AppleScript Editor. So I generally leave it in, but comment it out before copy/pasting into FileMaker's Perform AppleScript step.
July 26, 201015 yr This AppleScript is for looping thru the existing folders (top level only), deleting any where the name of the folder cannot be found in the specified field of the specified table of the specified database. I just used the names of a file I had handy. But I think you can see where to change them. The AppleScript asks you to choose the "root" folder which has these folders you want to test in it. Be sure to Backup your folder structure first. It is possible to delete all the folders. Especially if you use the System Events line instead of the Finder line. Finder is safer, as it just puts them in the Trash, but it means you can hardly use the computer while this is running, as the Finder is kind of busy. I've commented out the System Events line. You'd use one or the other lines (not both). Standard disclaimer: use at your own risk. -- Put your database, table and field name in the properties below -- BACKUP your folder structure BEFORE running! property DB_name : "Find 100" property table_name : "Products" property field_name : "SKU" tell application "FileMaker Pro Advanced" if not (exists field field_name of table table_name of database DB_name) then beep display alert "ERROR" message "Either the DB_name, table_name or field_name is wrong" as warning buttons {"OK"} default button 1 return end if end tell set root_folder to choose folder with prompt "Choose root folder containing folders to test" set root_folder_txt to root_folder as text set folders_list to list folder root_folder without invisibles repeat with folder_name in folders_list set keep to my fm_find_folder(folder_name) if keep is false then set bad_folder to root_folder_txt & folder_name tell application "Finder" to delete alias bad_folder -- puts in trash, safer, but keeps Finder busy -- Or -- tell application "System Events" to delete alias bad_folder -- deletes immediately, no trace left end if end repeat on fm_find_folder(folder_name) tell application "FileMaker Pro Advanced" tell table table_name of database DB_name try set theIDs to get ID of every record whose cell field_name = folder_name on error return false end try end tell end tell return true end fm_find_folder
July 26, 201015 yr i'd rather do this using applescript, my platform is mac os 10.6, using Filemaker Pro Advanced 11 and Filemaker Server 11 on a Snow Leopard Server. Don't underestimate the power of the dark side. Sorry, the Windows platform. Cross-platform compatibility is a very good thing. Having said that, I avoid third-party plug-in and I'd rather use native OS scripting than a plug-in. At the very least, check the platform before running the AppleScripts and code so that the process will handle the other platform gracefully. That may be a simple as issuing a dialog saying "This feature is not supported on this platform." but the trick is doing it at the start of the process. Remember that AppleScript is not supported on iOS mobile devices yet either. The Get( SystemPlatform ) function returns 3 for iOS. To check for Mac use Abs( Get( SystemPlatform ) ) = 1. Edited July 26, 201015 yr by Guest
July 27, 201015 yr Author wow, very fast answer, and it works like a charm thanks so much! let's spice things up, how do i tell the FileMaker to create the folder in a network disk (path /Volumes/IMCAS/..../FILEMAKER_DATA) ? I couldn't figure out how to configure this POSIX thing. Thank you very much for you help, Fenton
July 27, 201015 yr Author In addition, the script works great when i click on it, but can it do the job (creating one folder by ID) with the whole database at once? Thanks
July 27, 201015 yr 1. It can create a folder on a mounted volume, using the Unix syntax: /Volumes/volume name/folder path/ If there are spaces in the path, use: quoted form of "/Volumes/volume name/folder path/" As I noted in the AppleScript, you cannot just quote the whole thing, including the brackets {2009,2010,2011}, or else it just creates a single folder named: {2009,2010,2011} It is however slower to create them on the mounted volume. In either case, you may need to reset the OS access permissions on the folder afterwards; either via the Get Info options, or via a GUI app like BatChmod. 2. To do all records, you'd use a FileMaker Loop, in the FileMaker script. Then just use the AppleScript to create 1, but do it for each FileMaker record. Alternatively, you could gather all the IDs via AppleScript, then let it loop thru, using the repeat command. But, since you're a FileMaker developer, not an AppleScript developer, I'd use the Loop. It's fast either way.
July 28, 201015 yr Author ok, thank you so much. What script should i use in order to insert a button in the filemaker template, which action would be " open corresponding folder in Finder" ?? Once again, many apologies for my lack of knowledge. Regards
July 28, 201015 yr If you have no spaces you can use the simple Unix "open" command. Pseudo code: do shell script "open filepath" If you have spaces or problematic characters you'd use: do shell script "open quoted form of filepath" Rather than pasting into the Perform AppleScript native script text box, you can use the Calculated AppleScript option (radio button), then include the above, with the filepath part coming from a FileMaker field, assuming you have or can calculate a safe Unix path from a field(s). It is a little difficult to get the quotes to appear in the right place (as above). So it's best to create an unstored calculation to see the calculation result before trying; or view in Data Viewer using Script Debugger. Edited July 28, 201015 yr by Guest removed error capture method, not needed
Create an account or sign in to comment