AnsweredAssumed Answered

Open Record from Finder with Service (AppleScript)

Question asked by jbryan on Jan 16, 2018
Latest reply on Jan 22, 2018 by jbryan


I use BaseElements to create Finder folders & subfolders for each record in my Tactic table. And I have a button that can then open the Finder folder on my layout. This connects the working files associated with each Tactic to my solution without them being in the database. This works well for my team's needs. But now I'd like to do the reverse; Open the FM record from the Finder.



I've written an AppleScript that does the job by grabbing the ID from the folder name and passing that to a FileMaker script. But when I use Automator to add this script to the Services menu (MacOS), it no longer works as well. Followed instructions here. Seems to work well from the Automator interface but not consistently when it's actually called from selecting the Service (after control-click on the file in the Finder). Maybe there's a better method than Automator to create a Service?


Even stranger, when I add a global keyboard shortcut (instructions here) to the Service, it doesn't interact with FileMaker at all but just opens a new Finder window with the same 20 pixel offset I specify within my FileMaker script?!


  tell application "Finder"

  set theFolders to selection

  repeat with theFirst in theFolders

  set tacticNumber to text 1 thru 7 of (get name of theFirst)

  tell application "System Events"

  open location "fmp://XX.XXX.XXX.XX/Alfred.fmp12?script=OpenToTactic&$tacticNumber=" & tacticNumber as string

  delay 0.5

  end tell

  end repeat

  end tell


The "open location" calls a script in my solution and passes necessary parameters.

Here's the FM script "OpenToTactic":


Freeze Window

New Window [ Style: Document ; Using layout: "Tactic" (Tactic) ;

Top: Let ( [ Limit = Get ( WindowDesktopHeight ) - Get( WindowHeight ) ; Offset = Get( WindowTop ) + 20 ; Best = Min(Limit; Offset ) ] ; Best )
Left: Let ( [ Limit = Get ( WindowDesktopWidth ) - Get ( WindowWidth ) ; Offset = Get ( WindowLeft ) + 20 ; Best = Min ( Limit ; Offset ) ] ; Best )
Enter Find Mode [ Pause: Off ]
Set Field [ Tactic::Tactic # ; $tacticNumber ]
Perform Find [ ]
Go to Related Record [ From table: "Tactic" ; Using layout: "Tactic Detail" (Tactic) ]


Thoughts? Recommendations?

I'm open to rewriting anything that's awry. I'm putty in your hands. Mold me.