Introduction to PHP for Os X by Example

Using Automator with PHP

PHP scripts can be run from Automator.

You can pass invocation arguments to the script.

And you can get output back from the script.

This is a simple and quick way to wrap a GUI around a PHP script.

Resources

Examples – phpauto.pl / phpauto.workflow / phpauto.php (zip, 128kb)

Creating the Automator Example

  • Open Automator, /Applications/Automator.app
  • All of the actions you need are standard to Automator except one, ‘Get UNIX Paths of Files’.
    1. To import this action open the File menu then select Import Actions.
    2. Navigate to the folder containing the action and select the file (/Users/[shortname]/PerlXWorldIII/resources/Get UNIX Paths of Files.action). Note: This action is available for download from Automatorworld.
  • Drag the following actions in this order from the Library and set them as described.
  • Get Specified Finder Items – Make sure that ‘Show Action When Run’ is checked.
  • Get UNIX Paths of Files – Check ‘Add Quotes…’
  • Run Shell Script – Select ‘Script File’ and navigate to the file phpauto.php and select it. Check ‘Use input as arguments’
  • Run AppleScript – Type the following script just as it appears here.
on run {input, parameters} display dialog input buttons {"OK"} default button 1 return input end run
  • Save the file as an application in the same directory as the PHP script.

OK. So what does it do?

It doesn’t do much, really, but it does show the potential of using Automator with PHP script.

When you run the workflow application a dialogue will pop up for you to select a series of files. Once selected, hit the Continue button. An AppleScript dialogue should pop up next with the list of the files and their paths in it.

Fig. 1 The autophp.workflow Fig. 1 The autophp.workflow