gpt4 book ai didi

objective-c - 从 cocoa 应用程序中查找软件包安装程序(如 DivX Installer.package)是否正在运行

转载 作者:行者123 更新时间:2023-12-03 17:21:24 26 4
gpt4 key购买 nike

我不知道这是否可能,所以我希望这个问题不会显得愚蠢:我可以进入 cocoa 应用程序,甚至使用 bash 脚本,获取特定正在运行的应用程序的 pid。这样我就可以采取行动(例如发出警报并询问您是否要关闭它)。我们可以对包(pkg)进行同样的操作,以某种方式知道它的 id(如“org.someIdentity.pkg”)吗?

编辑这就是我在 cocoa 中使用的:

    - (void)unWantedApp:(NSNotification *)notification {
NSDictionary *userInfo = [notification userInfo];
NSLog(@"userInfo == %@", userInfo);

if ([NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.blabla"] || [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.blabla2"]) {
[[NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"blabla is running..", nil), [[NSBundle mainBundle] objectForInfoDictionaryKey:(NSString *)kCFBundleNameKey]]
defaultButton:nil alternateButton:nil otherButton:nil informativeTextWithFormat:NSLocalizedString(@"Well, I hope you are not joking with more then one Tool at same time...", nil)] runModal];


}
}

编辑

我在 bash 中使用的内容:

isOpen=$(ps auxwww | grep '/Applications/blabla.app' | grep -v 'grep' | wc -l)
if [ -e '/Applications/blabla.app' ]; then
if [ $isOpen -ge 0 ]; then
# do what you are intresting for... But a packages is not in Application folder and is opened by Installer.app :-(
fi
fi

编辑bash 脚本也可以在 cocoa 中以这种方式使用:

#include <stdio.h>
#include <stdlib.h>

#define SCRIPT "\
#/bin/bash \n\
if [ -e '/Applications/blabla.app' ];then\n\
#variable and other statement here(escape all special caracter and manually add the new line ->> \n)\n\
else\n\
exit 0\n\
fi"

int main()
{
system(SCRIPT);
return 0;
}

最佳答案

也许这有点帮助:

app=${1:-VirtualBox}   #tested on it

run_searched() {
echo "The installer installing $1 as: $2"
}
run_other() {
echo "The installer NOT installing $1. (but installing: $2)"
}
not_running() {
echo "The installer is not running"
}

isasdir="$HOME/Library/Saved Application State/com.apple.installer.savedState"
isasfile="$isasdir/windows.plist"
if [[ -d "$isasdir" && -f "$isasfile" ]]
then
win=$(plutil -p "$isasfile" | grep '"NSTitle"' | sed 's:.*"NSTitle".*=>.*"\([^"]*\)":\1:')
if [[ "$win" =~ $app ]]
then
run_searched "$app" "$win"
else
run_other "$app" "$win"
fi
else
not_running
fi

关于objective-c - 从 cocoa 应用程序中查找软件包安装程序(如 DivX Installer.package)是否正在运行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25893138/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com