Posts from the 'Utility' Category

Use FileMaker Pro 9 to connect to a SQL / MySQL data source

One of the really powerful features of FileMaker Pro 9 is the ability to connect directly to an SQL data source. This means you can create a FileMaker 9 interface for your clients and allow them to add/modify/browse/delete records on a SQL data source.

Setting up FileMaker Pro 9 to connect to a SQL data source is actually a little more complicated than the FileMaker marketing would have you believe. In this short tutorial, we’ll talk you through the steps of connecting to a MySQL data source using FileMaker Pro 9 on a Mac and Actual Technology’s ODBC drivers (yep, you need third party software – surprised?)

There are two steps to setting up your FileMaker to MySQL connection:

1) Set up your ODBC preferences
2) Set up FileMaker Pro 9

1) Set up your ODBC preferences

The first thing to do here is to go to Actual Technologies and get a copy of the ODBC driver you require. (NB. Metaclarity is not affiliated with Actual Technologies in any way – we just like their software). We’re running MySQL so we bought a copy of the Open Source Databases driver. If you don’t want to spend money on a driver there are some free drivers available on the internet, but for $29 Actual will make your task a LOT easier.

  • Run the Actual ODBC Driver Pack installer
  • Go through the legal steps then click customize and choose the driver you want to install: we only installed the “Actual ODBC Driver for Open Source Databases” as that was all we required to connect to MySQL
  • With the installation finished successfully go to the Utilities folder on your drive and open the application called: “ODBC Administrator”
  • Click on User DSN then click on the “Add… button”
  • Select Actual’s Driver in the list that appears.
  • Press “Continue” in the new pop-up window.
  • Choose an easy to remember name for your connection and description – these are not critical to the connection. For DSN type, choose System.
  • Choose your database type (here we chose MySQL)
  • Enter the IP for your MySQL server in the Server field. Port is usually 3306.
  • Set your username and password for connecting to your online MySQL database in Login ID and Password.
  • In the next window the name of your database should be available in the Database popup field. Select it now then press continue. Then press “Done”

Now in the ODBC Administrator application under the System DSN tab you’ll see your data source and you’re ready to connect with FileMaker Pro 9

2) Set up FileMaker Pro 9 to connect to SQL / MySQL

  • Launch FileMaker Pro 9
  • Create a new empty database.
  • Open the define database dialog: File>Manage>Database…
  • Go to Relationships and double click on the existing “test” table
  • For Data Source, choose Add ODBC data source….
  • Choose your MySQL source from the list and press “Continue…”
  • Most of the defaults in the following screen are fine though if you don’t want to be prompted for a password each time you connect then use “Specify user name and password”
  • Now choose the table you want to connect to and read. Your table will populate with the fields from this remote table.
  • Press OK and watch what happens – you’re using FileMaker Pro 9 to access a remote SQL data source! You can now use FileMaker’s layout functions etc. to make this layout more attractive and get to work on learning how to better integrate Filemaker Pro 9 and MySQL!

Use BBEdit UNIX Filters to Format Javascript

Here’s a tip specifically for people who use BBEdit to write Javascript.

If you copy a lot of Javascript examples from the web you probably end up with code that hugs the left edge of your BBEdit window like this (for example):

var txt=""
function message()
{
try
{
adddlert("Hey There!")
}
catch(err)
{
txt="An error has occurred"
alert(txt)
}
}

But you want it indented and nicely formatted, right?

Well, we found a link on the web [ http://attaboy.tumblr.com/post/20570385 ] that sort of explained how to put together a BBEdit UNIX Filter to do just that, but we also bashed our brains out for about an hour before realising that to call a PHP Shell Script in a UNIX Filter you need to wrap this around the code:

#!/usr/bin/php
<?php
[... your code...]
?>

Obvious to some – not to all of us!!

So we’ve put together the complete script to format Javascript from BBEdit here for downloading:

http://www.metaclarity.com/dl/JavaScriptFormatPHP.zip

Unzip it and put it in this folder:
~/Library/Application Support/BBEdit/Unix Support/Unix Filters/

Select your “flat” Javascript in the BBEdit window. Run the filter (from the !# menu or from Palettes>UNIX Filters) and it should format your Javascript!

Good luck!

Use rsync to backup your Mac to a remote server via SSH

If you find online backup solutions expensive and heavy on your system, you might be pleased to hear there is a cheap, easy way to create a mirror backup your Mac (or other UNIX variant) to a secure online server. And as of Mac OS X Leopard, rsync will even transfer metadata associated with your files like Tags and Comments.

This method does not allow you to roll back to previous dated backups like certain backup solutions do (Time Machine, for example). What it does is create a mirrored backup of your Mac on a remote server, so it’s best used in conjunction with a local hard-drive based incremental backup solution.

Still, if the house burns down your files will be safe and once you’ve done the initial backup, rsync is very efficient at keeping your remote backup mirrored with your disk.

In this example we’re going to backup the currently logged-in user’s Documents folder.

What you’ll need:

-rsync running on you Mac (it’s there on 10.4 and 10.5)
-An Internet Service Provider (ISP) who allow you to connect via SSH. [examples 1 2 3]

Procedure:

Step 1 – Set up the remote server

  • You’re going to need shell access to your server. If you don’t already have it and you use cPanel to administer your server then there is often a “Request Shell Access/Remote Login” option. If there isn’t, contact your ISP directly.
  • With shell access set up, create a folder that is outside of the scope of your webserver. You could use FTP to do this, if you prefer. For example, set up a folder called private_BKP at the root level of your server and put a folder in there called Mac_One_BKP. The path is then /home/private_BKP/Mac_One_BKP and its in there that we’re going to put the contents of our Documents folder.

Step 2 – Set up your Mac

  • Launch the Terminal application (found in your Utilities folder).
  • Type rsync -avz -e ssh /Users/yourUserName/Documents yourLoginName@yourServer.com:'/home/private_BKP/Mac_One_BKP'
    An easy way to do the first part is to type rsync -avz -e ssh then drag and drop your Documents folder right into the Terminal window. Watch out that your system does not add a slash ‘/’ after the word ‘Documents’. If it does, just remove it. Why? The slash will mean rysnc will copy the contents of the Documents folder rather than copying the whole folder.
  • For the second part, you need to guarantee that ‘yourLoginName@yourServer.com:’/home/private_BKP/Mac_One_BKP’ is pointing to the folder you created on your remote server.
  • Before starting the transfer, you may want to exclude certain files and folders from being sent to the server (very private stuff, caches, etc.) To do this, see Step 3 – Deletes and Excludes below.
  • Press Return and you’ll be asked for your password. Provide it and you should see a long list of files scrolling in the Terminal window. These are the files moving from your machine to the remote server.

Note 1: If you want to checkout what the -avz -e stuff does, take a look at the rsync man page
Note 2: Your first backup can take hours, if not days (don’t worry – it’ll be MUCH faster the second time round thanks to rsync’s ability to transfer only the parts of files that have changed. Take a break from the computer and have a buy a real copy of this instead) this instead

Step 3 – Deletes and Excludes

One you’ve backed-up your Mac’s Documents folder using the method above there will come a time when you will want to run the script again – like when you add new content to your folder! However, you many also have deleted some content from your Documents.

  • To have rsync delete files on the remote server that are no longer on your machine, add --delete
    ex: rsync -avz --delete -e ssh /Users/yourUserName/Documents [etc.]
  • To have rsync exclude the transfer of certain files to the remote server , add --exclude='myFileName'
    ex: rsync -avz --delete --exclude='myFileName' -e ssh /Users/yourUserName/Documents [etc.]
    You can add multiple –exclude statements or add a list via an –exclude_from file (see the manual)

Disclaimer

Metaclarity does everything it can to ensure the information we post is accurate. However, Metaclarity can accept no responsibilty for any damage or loss of data use of the above information might cause.