Managing Files with AppleScript

If you’re like most power FileMaker users, you’ve discovered that it’s a great tool for managing collections of things or for gathering disparate data sources for reporting. So you’ve probably wanted at some point to do one or more of these actions:

  • Get a list of files on your computer
  • Import a batch of files
  • Move files on your computer
  • Read the text of a file that doesn’t import correctly (e.g., HTML)

Does that sound familiar? Unfortunately, FileMaker provides limited functionality for these operations. Here’s a few handy custom functions for you Mac OS users to help you access the power of interacting with files on your computer. Each generates AppleScript that you can then run from a script using the Perform AppleScript command. Here are the core functions included:

  • AppleScriptDirPath
  • AppleScriptFilePaths
  • AppleScriptFilePathsInDir
  • AppleScriptMoveFiles
  • AppleScriptReadFile

Each function presents the user with an OS-native dialog and returns a list of paths to the files selected or moved. No plug-ins required!

Yes, this is another Mac-only demo (sorry Windows users!). But that’s only because this technique arose out of a Mac-only situation. You could do something similar on Windows using the Send Event script step. You Windows users out there are more than welcome to post your versions of the functions. We’d love to make the demo cross-platform compatible.

FileMaker Pro users, don’t despair. You can use these functions too. Each command shows you the AppleScript that it runs. So just copy and repurpose that text to have a fully functional AppleScript that you can paste into your scripts.

Have you done something similar or tweaked these functions for other purposes? Tell us about it in the comments!

Download demo file:  Demo_ManagingFilesWithAppleScript_2012.02.20

Demo History:
Nov 11, 2011: added function for reading file contents; now accepts multiple resuts from AppleScript
Aug 12, 2011: enhanced error handling and function readability; moving files now returns list of destination paths
Feb 20, 2012: fixed bug with copying moved files; added support for FileMaker Pro; enhanced handling of files with “.” in their name

Leave a Reply