Shortening URLs using FileMaker

Update: 2012-11-27 At the request for reader Robin, I had a closer look at this and it seems that both Google and have gone to POST method (rather than the simpler GET method) and are more locked down. They both now require an API key.

You could build a method for this approach, but you have to use a plug-in, such as ScriptMaster or AppleScript to CURL out a calculated POST request. The other services employ GET methods, constructing it in a URL.

The only one from the original demo that seems to work is

Sorry, but such is life on the Internet. Change is constant.

Update: 2011-01-25 – Added a standalone script to the demo database, designed to easily copy and paste into your own solution. Details are here.

Shortening long URLs is all the rage these days, driven by the use of Twitter. The 140 character limit that Twitter has imposed means that every character in a message is valuable and anything that can be done to shorten the message is useful. It is probably worth thinking about where you are going to use these shortened URLs as they are, by their nature, more transient than fixed URLs. If the URL shortening service is closed, the shortened URLs will cease to work. That said, they have application for transient communication such as Twitter feeds.

There are a number of methods using AppleScript to turn long URLs into short URLs, using services like I was inspired by these articles to try and get this technique working in FileMaker. It turns out it is very straight forward and requires no AppleScript, so this ends up being a FileMaker file that can work well on Mac or Windows and even with FileMaker Go. The obvious benefit of doing this work in FileMaker is that you can apply it to large numbers of URLs quickly, instead of a one by one method employed in the AppleScript/Automator approaches. It also allows you to generate these shortened URLs programmatically.

The basic approach here is to employ a Web Viewer in FileMaker, sending it a calculated URL and then grab the result back (using GetLayoutObjectAttribute(“WebViewerName”, “content”)) and stuff it into the Shortened URL field.

Sounds pretty simple right? I managed to make it a little more complicated by adding the ability to swap out URL shortening services. I started with, and added a few others that people mentioned in their articles. Fortunately the syntax is pretty much the same for all of their APIs, so if one of them goes out of business (how do they stay in business anyway?) it should be fairly easy to move on to another service.

Let’s dive right in and have a look at how this is setup in the Demo File.

1) Main Screen – URLs


The first layout is where the work happens. You enter your long URLs, then press the ‘Shorten’ button to shorten a single URL, or the ‘Shorten Batch of URLs’ to shorten everything you have entered. The ‘Test’ button allows you to test the newly created Short URL.

2) Services layout


The Services layout is to add new URL Shortening services. is by far the most popular, but there are others. If these ones go out of business, you can always add more assuming they have a similar API approach. Look around on their web site for ‘API’ and see how they suggest formatting the request for a shortened URL.

3) Inspiration layout


This is a list of articles I looked at for ideas and inspiration. If you are on a Mac, please read the articles, as they describe setting up Applescripts to use with Automator Services.

The Scripts


I have two main scripts, ‘Shorten URL’ will shorten a single URL. ‘Shorten a Batch of URLs’ will shorten the entire Found Set. The other scripts are for navigation within the database.

Shorten URL script


This is pretty self explanatory if you read through the comments.

• Set the URL to a variable called $URL. If there is an ‘http://’ in it, remove it.
• Select a web service to use, set the base URL to the variable $APIURL
• Combine the $APIURL and the $URL variables into a string to send to the web viewer.

What this will look like with the example is ‘’ and ‘’

• Set the Web Viewer to the calculated URL ($APIURL&$URL) to create a new short URL
• Run a timed loop waiting for the Web Viewer to have something in it. Don’t exit until there is a result.
• Once there is something returned from the Web Viewer, set the text in the Web Viewer (the content) to a variable called $result

This employs GetLayoutObjectAttribute(“WebViewerName”, “content”) to return the content of the Web Viewer

• Exit the loop once there is something in the $result variable
• Set the Shortened URL field to the $result variable
• Clear the Web Viewer, ready for the next run.

On the main layout, add a Web Viewer object


Name the Web Viewer something like ‘URLShorteningWebViewer’ or whatever you reference in your script. I like to name my objects by what they are and what I am going to use them for, in case I end up using multiple Web Viewers in my solution.

Set up the Web Viewer


I turned off all the interaction options, set the Web Address to nothing and set the the border to Line width to ‘None’, so it is basically hidden on the layout. The Web VIewer flashes briefly when something loads in the text, but the user has to be watching for it.

Shorten a Batch of URLs script


This is a simple looping script that starts at the first record and then moves through the Found Set. On each record, the batch script runs the ‘Shorten URL’ script.

Those are the basic techniques employed in this solution. You should be able to copy and paste the two scripts into your own solution with only minor modifications. Change the fields to match them as named in your solution. You don’t have to do an entire data table for Services, you could just pick one that you are going to support and put that into a global field. If goes away, you would have to come in and change it to the new services API.

I hope this is useful, please give me feedback if you don’t understand something or have suggestions for improvements.

Download Demo File here.

Integrating with Twitter – Further Development


There are a number of articles on integrating Twitter further with FileMaker. Google ‘FileMaker and Twitter’ to find more.

Lauren Kuhlman has an AppleScript driven approach.

FMWebSchool has a database called ‘FMTweet’, with an example of posting to Twitter from a FileMaker database, but I could not see a direct link to download it. You may need to sign up for their newsletter to get access to it. I looked at the structure of it and it seemed like more steps than necessary.

One of the best implementations of Twitter in FileMaker that I have seen is the work done for the 2010 FileMaker DevCon2Go Scheduler. (to log into the file with developer access, hold down the Shift key when launching. User: admin, password: devcon) It includes a Twitter stream following ability as well as a way to post directly to Twitter from within FileMaker. Combining the ability to generate shortened URLs with these capabilities might be an interesting project.

Related Articles:
URLs in PDFs – Yet another reason to shorten URLs in FileMaker
Creating and Storing 2D Bar Codes in FileMaker
Making FileMaker interact with Google Translate


  1. URLs in PDFs – Yet another reason to shorten URLs in FileMaker « HomeBase Software - January 25, 2011

    […] readers of this blog will recall I wrote on the topic of URL Shortening in FileMaker recently, and created a demo database that does just that. I have updated this database to include a new […]

  2. Shrinking Batches of PDF Files on a Mac for FileMaker Server 12 | HomeBase Software - July 12, 2012

    […] Related Articles: URLs in PDFs – Yet another reason to shorten URLs in FileMaker Shortening URLs using FileMaker […]

  3. How do I update information in a whole bunch of records at once in FileMaker? | HomeBase Software - July 13, 2012

    […] Related Articles: Highlighting Rows in FileMaker lists or portals ‘Type Ahead’ Style Searching through Portals in FileMaker Pro Shortening URLs using FileMaker […]

  4. Move Selected Files into a New Folder using AppleScript and Automator | HomeBase Software - July 13, 2012

    […] Related Articles: Growl Integration with FileMaker Shortening URLs using FileMaker […]

  5. URLs in PDFs – Yet another reason to shorten URLs in FileMaker | HomeBase Software - July 14, 2012

    […] Articles: Shrinking Batches of PDF Files on a Mac for FileMaker Server 12 Shortening URLs using FileMaker Blast from the Past: FileMaker Pro […]

%d bloggers like this: