从应用程序的名称,反之亦然获取进程名,使用AppleScript [英] Get process name from application name and vice versa, using Applescript

查看:456
本文介绍了从应用程序的名称,反之亦然获取进程名,使用AppleScript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在27 2003年2月,苹果公司的员工克里斯托弗·内贝尔说,他想理顺的这个问题中所报告的比尔奇斯曼:


  

由于不同的命名为应用程序和应用
  在某些情况下流程,我们最终不得不写咯
  令人困惑的脚本是这样的(如果我们已经更名为Adobe公司的Photoshop 7.0
  Photoshop的在Finder):

 告诉应用程序的Photoshop来激活
告诉应用程序系统事件
告诉应用程序软件Adobe Photoshop 7.0


我只想说,它仍然是在2011年8月的一个问题,我继续运行到它,所以我希望在这里计算器的好乡亲可以帮助找到一个解决办法;在此先感谢!

给定一个应用程序名(即东西我可以指示为启动),我希望能够这个名字传递给一个子程序找到相应的进程名。反过来,给定一个进程名,我希望能够将它传递给一个子程序找到对应的应用程​​序名称。

有什么建议?


解决方案

以下code就足够了。它绘制,在一定程度上,在fireshadow52的回答并在在MacScripter.net 的一个职位。

 上GetApplicationCorrespondingToProcess(PROCESS_NAME)
    告诉应用程序系统事件
        设置process_bid获取进程PROCESS_NAME的包标识符
        APPLICATION_NAME设置为文件(应用程序,其中包标识为process_bid)
    告诉结束
    返回APPLICATION_NAME
结束GetApplicationCorrespondingToProcess在GetProcessCorrespondingToApplication(APPLICATION_NAME)
    告诉应用程序系统事件
        设置为APPLICATION_ID(获取应用程序的ID的Adobe Acrobat专业作为字符串)
        设置为PROCESS_NAME名称(应用程序,其中包标识为APPLICATION_ID)
    告诉结束
    回报PROCESS_NAME
结束GetProcessCorrespondingToApplication - 实例:
显示对话框(GetProcessCorrespondingToApplication(使用Adobe Acrobat专业版)作为字符串)
显示对话框(GetApplicationCorrespondingToProcess(Acrobat中)作为字符串)

On 27 February 2003, Apple employee Christopher Nebel said he'd like to straighten out this problem as reported by Bill Cheeseman:

Because of the different naming for applications and application processes in some circumstances, we end up having to write slightly confusing scripts like this (if we've renamed Adobe Photoshop 7.0 to "Photoshop" in the Finder):

tell application "Photoshop" to activate
tell application "System Events"
tell application process "Adobe Photoshop 7.0"

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆