本文介绍了从应用程序的名称,反之亦然获取进程名,使用AppleScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在27 2003年2月,苹果公司的员工克里斯托弗·内贝尔说,他想理顺的中所报告的比尔奇斯曼:
Suffice it to say, it's still a problem in August 2011, and I keep running into it, so I hope the good folks here at StackOverflow can help find a workaround; thanks in advance!
Given an application name (i.e. something I can instruct to activate
), I'd like to be able to pass that name to a subroutine to find the corresponding process name. Conversely, given a process name, I'd like to be able to pass it to a subroutine to find the corresponding application name.
Any suggestions?
解决方案
The following code suffices. It draws, to some extent, upon fireshadow52's answer and upon a post at MacScripter.net.
on GetApplicationCorrespondingToProcess(process_name)
tell application "System Events"
set process_bid to get the bundle identifier of process process_name
set application_name to file of (application processes where bundle identifier is process_bid)
end tell
return application_name
end GetApplicationCorrespondingToProcess
on GetProcessCorrespondingToApplication(application_name)
tell application "System Events"
set application_id to (get the id of application "Adobe Acrobat Professional" as string)
set process_name to name of (application processes where bundle identifier is application_id)
end tell
return process_name
end GetProcessCorrespondingToApplication
-- Example usage:
display dialog (GetProcessCorrespondingToApplication("Adobe Acrobat Professional") as string)
display dialog (GetApplicationCorrespondingToProcess("Acrobat") as string)
这篇关于从应用程序的名称,反之亦然获取进程名,使用AppleScript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!