Lo siguiente AppleScript devolverá la ruta de la aplicación si se está ejecutando. También devolverá las rutas de todas las instancias de la aplicación que se estén ejecutando, si hay más de una (sin necesidad de un repeat
bucle).
property singleAppPath : missing value
property multipleAppPaths : missing value
tell application "System Events"
set searchedApps to a reference to ¬
((every application process) whose name contains "Acrobat" or ¬
displayed name contains "Acrobat")
if (count of searchedApps) is 1 then
set singleAppPath to POSIX path of application file of searchedApps as text
else if (count of searchedApps) > 1 then
set multipleAppPaths to POSIX path of application file of searchedApps
end if
end tell
Me doy cuenta de que el siguiente código no es realmente una solución directa a la pregunta del OP. Sin embargo, se me ocurrió que, una vez que la ruta completa del archivo de la aplicación se recupera desde el código anterior en mi solución otras personas, incluido yo mismo, puede encontrar valiosa para tener una opción para revelar la aplicación / en el Finder. Esto resulta especialmente útil si el proceso de aplicación que busca no proviene de una aplicación ubicada en su carpeta /Aplicaciones.
property searchedApps : missing value
property singleAppPath : missing value
property multipleAppPaths : missing value
activate
set theAppProcess to (display dialog ¬
"Reveal App From App Process Search" default answer ¬
"Search For ..." buttons {"Cancel", "Get Full Path", "Reveal In Finder"} ¬
default button 3 cancel button 1 ¬
with title "Locate Application Process" giving up after 45)
if button returned of theAppProcess is "Get Full Path" then
getFullAppPathFromSearchedProcesses(text returned of theAppProcess)
if singleAppPath != missing value then
activate
display dialog singleAppPath buttons {"OK"} default button "OK"
end if
else if button returned of theAppProcess is "Reveal In Finder" then
getFullAppPathFromSearchedProcesses(text returned of theAppProcess)
revealApp()
end if
on revealApp()
if (count of searchedApps) is 1 then
do shell script "open -R " & quoted form of singleAppPath
else if (count of searchedApps) > 1 then
repeat with thisItem in multipleAppPaths
do shell script "open -R " & quoted form of thisItem
delay 0.1
end repeat
end if
end revealApp
on getFullAppPathFromSearchedProcesses(appName)
tell application "System Events"
set searchedApps to a reference to ¬
((every application process) whose name contains appName or ¬
displayed name contains appName)
if (count of searchedApps) is 1 then
set singleAppPath to POSIX path of application file of searchedApps as text
else if (count of searchedApps) > 1 then
set multipleAppPaths to POSIX path of application file of searchedApps
end if
end tell
return {singleAppPath, multipleAppPaths}
end getFullAppPathFromSearchedProcesses