本文介绍了如何检查是否选择关键是在MAC的bash应用启动pssed $ P $的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到了一个比较简单的问题。

I got a relatively simple question.

我有写在bash发射了几Mac应用程序。
我想一个小功能添加到发射装置,通过让别人访问config.app或别的东西位于/内容/资源,当他们preSS的'选项/ ALT在应用程序的启动键。有点像iTunes或iPhoto中,在那里你可以访问一个小菜单选项。

I have a few mac applications that have launchers written in bash. I wanted to add a little feature to the launchers, by letting others access a config.app or something else located in /Contents/Resources, when they press the 'option/alt' key at the startup of the app. Kinda like iTunes or iPhoto, where you can access a little options menu.

我不知道code应该什么样子时,它纯粹是在bash;我发现了几个例子,让使用AppleScript的和/或可可挂钩,但没有纯粹在bash。

I don't know how the code should look like when it's purely in bash; i found a few examples that make use of applescript and/or cocoa hooks, but none purely in bash.

是这样的:如果'optionKeyDown';然后打开$ WORKDIR /../资源/ config.app

或者,这是不可能的纯bash中呢?

Or is this not possible in pure bash at all?

推荐答案

这里有一个很好的解决方案:的

There's a good solution here: http://lists.apple.com/archives/applescript-users/2009/Sep/msg00374.html

看看下面code:

#import <Carbon/Carbon.h>

int main (int argc, const char * argv[]) {
    unsigned int modifiers = GetCurrentKeyModifiers();

    if (argc == 1)
        printf("%d\n", modifiers);

    else {

        int i, result = 1;
        for (i = 1; i < argc; ++i) {

            if (0 == strcmp(argv[i], "shift"))
                result = result && (modifiers & shiftKey);

            else if (0 == strcmp(argv[i], "option"))
                result = result && (modifiers & optionKey);

            else if (0 == strcmp(argv[i], "cmd"))
                result = result && (modifiers & cmdKey);

            else if (0 == strcmp(argv[i], "control"))
                result = result && (modifiers & controlKey);

            else if (0 == strcmp(argv[i], "capslock"))
                result = result && (modifiers & alphaLock);

        }
        printf("%d\n", result);
    }
    return 0;
}

将其粘贴到一个名为,例如keys.m。

Paste it into a file called, e.g. keys.m.

然后建立一个命令行实用程序是这样的:

Then build a command line utility like this:

$ gcc keys.m -framework Carbon -o keys

可执行某处在你的路径,例如的/ usr / local / bin目录,甚至只是在相同的目录bash脚本,那么你可以称呼其为如键选择并为您0,返回的字符串或1。

Put the keys executable somewhere in your path, e.g. /usr/local/bin, or even just in the same directory as your bash script, then you can call it as e.g. keys option and check the returned string for "0" or "1".

这篇关于如何检查是否选择关键是在MAC的bash应用启动pssed $ P $的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 04:49