An AppleScript can be used, for example:
# on run {args, parameters} -- use this declaration for a Run AppleScript action in Automator on run args -- script run from the editor or Script Menu, or app double-clicked set useFinderSelection to false -- set to true to use the Finder selection if no arguments set processedItems to {} if args is not in {{}, missing value, current application, me} then -- command line or Automator arguments? repeat with anItem in args try set anItem to POSIX path of anItem if isDirectory(anItem) then doStuff("cd " & quoted form of anItem) set end of processedItems to anItem end if on error errmess -- oops log errmess end try end repeat else if useFinderSelection is true then set processedItems to doFinderSelection() end if if processedItems is {} then doStuff("") -- just the default working directory end run to doFinderSelection() -- handle folders in the current Finder selection tell application "Finder" to set theSelection to (get selection as alias list) set processedItems to {} repeat with anItem in theSelection if contents of anItem is not (path to me) then -- application will be selected if double-click set anItem to POSIX path of anItem if isDirectory(anItem) then doStuff("cd " & quoted form of anItem) set end of processedItems to anItem end if end if end repeat return processedItems end doFinderSelection to doStuff(theScript) -- open a new Terminal window with random background color, running theScript if application "Terminal" is running then set {r, g, b} to {16383 * (random number from 0 to 4), 16383 * (random number from 0 to 4), 16383 * (random number from 0 to 4)} -- 125 possible colors tell application "Terminal" activate do script theScript -- a script of "" just creates a new window set background color of window 1 to {r, g, b} if (r + g + b) / 3 > 21845 then -- try to make the text color contrast set normal text color of window 1 to {0, 0, 0} -- black else set normal text color of window 1 to {65535, 65535, 65535} -- white end if end tell else tell application "Terminal" launch -- avoid multiple windows do script theScript -- default window activate end tell end if end doStuff on isDirectory(posixPath) -- check if a file item is a directory or bundle set posixPath to quoted form of posixPath set determination to (do shell script "/usr/bin/file -b " & posixPath) if determination contains "directory" then return true return false end isDirectory on open fileItems -- items dropped onto the app (only needed for a droplet) repeat with anItem in fileItems set anItem to POSIX path of anItem if isDirectory(anItem) then doStuff("cd " & quoted form of anItem) end repeat end open
Edit:
Updated the script to be able to be run from a script editor or the Script Menu*, from the command line via osascript, or saved as a script applet or droplet. With a slight change to the run handler parameters, it can also be run from a Run Script action in Automator. It looks for directories in any file arguments (command line or dropped onto the droplet, otherwise optionally the current Finder selection), and opens a new Terminal window with a random background color for each one found, running a script in the window that changes the working directory to the folder. If there are no arguments or Finder selection, a new window is created at the default working directory.
*The Script Menu (enabled according to the Script Editor preference) is a status item menu on the right side of the main menu bar that uses scripts (or aliases to them) that you put in your user's ~/Library/Scripts folder. If a script is placed in the main folder, it will always be in the menu, otherwise it can be placed in a folder named for the application in the Applications subfolder (create folders as needed), where it will only be in the menu when that application is active.