We are using AppleScript to reveal files from our application in the Finder. If a user has alternatives, e.g., PathFinder, installed as a replacement for Finder, how we can find our what application to tell the AppleScript commands?
2 Answers
You can try using this:
try
tell application "Path Finder" to reveal "/Users/danielbeck/Downloads"
on error
tell application "Finder" to reveal folder "Downloads" of home
end try
But this assumes that a user with Path Finder prefers it for the reveal functionality.
Alternatively,
do shell script "open 'file:///Users/danielbeck/Downloads'"
When a user has configured Path Finder to handle file:// URLs, this will open the folder in Path Finder. Only works with folders though.
You can use the following to get a list of processes:
tell application "System Events"
processes
end tell
Look for a process named Finder. If not found, the user has no running Finder. Or look for one named Path Finder, and if found, use it instead. Etc.
- 109,300
- 14
- 287
- 334
-
Unfortunately, configuring Path Finder to handle *Reveal* actions from other applications doesn't extend to AppleScript. – Daniel Beck Mar 12 '11 at 08:33
While @Daniel Beck has provided a good answer above, here is a handler I use to reveal in Finder the item currently selected in Path Finder. Often I need to do something in the Finder window, so I have added a pause until the Finder window name is the same as the Path Finder window name.
For future reference, I'm maintaining this snippet in my GistHub at: revealPFItemInFinder.applescript
```applescript
--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
on revealPFItemInFinder()
--–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
(* VER: 2.0 2018-03-15
PURPOSE: Reveal Item in Finder that is Selected in Path Finder
RETURNS: alias of item selected in both Finder and Path Finder
AUTHOR: JMichaelTX
--–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––
*)
--- GET THE ITEM SELECTED IN PATH FINDER ---
tell application "Path Finder"
set fileList to (get selection)
if ((fileList is missing value) or ((count of fileList) ≠ 1)) then error ("You must select only ONE file in Path Finder.")
set pfWinName to name of window 1
set itemPath to POSIX path of item 1 of fileList
end tell
set itemAlias to alias POSIX file itemPath
--- REVEAL SAME ITEM IN FINDER ---
tell application "Finder"
activate -- to make sure reveal will be in frontmost window
reveal itemAlias
--- Now Wait for New Finder Window with Same Name as Path Finder ---
set finWinName to name of window 1
set maxWaitTime to 2.0
set delayTime to 0.1
set waitTime to 0
repeat while finWinName ≠ pfWinName
delay delayTime
set finWinName to name of window 1
set waitTime to waitTime + delayTime
if (waitTime > maxWaitTime) then error "Max wait time of " & maxWaitTime & " exceeded waiting for Finder Window of " & pfWinName
end repeat
end tell
return itemAlias
end revealPFItemInFinder
```
- 101
- 2