gpt4 book ai didi

objective-c - 安装首选项 Pane 时运行安装脚本

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

我已经编写了一个 ruby​​ 脚本,现在我正在考虑将其包装在首选项 Pane 中,以便配置我的 ruby​​ 脚本。现在我希望有一种方法可以让我在安装此首选项 Pane 时运行一些任意命令,以便安装必要的 ruby​​ gems 等,但是我似乎无法在任何地方找到有关此类功能的任何文档。

任何想法将不胜感激。

干杯尼克

最佳答案

您可以调用一个 ruby​​ 脚本来为您执行任何必要的配置。如果您需要它来安装 gem,您可能需要以提升的权限运行它。这就是我过去的做法:

// Get the path to the helper script from the main app bundle
NSBundle *appBundle = [NSBundle mainBundle];
NSString *scriptPath = [appBundle pathForResource: @"helperScript"
ofType: @"rb"];

// Construct the applescript command to run to helper script with elevated privileges
NSString *scriptCommand = [NSString stringWithFormat: @"do shell script \"ruby '%@'\" with administrator privileges", scriptPath];

// Execute the helper script via Applescript, log any errors
NSAppleScript *executeRubyScript = [[NSAppleScript alloc] initWithSource: scriptCommand];
NSDictionary *error = [[NSDictionary alloc] init];
[executeRubyScript executeAndReturnError: &error];
[executeRubyScript release];

关于objective-c - 安装首选项 Pane 时运行安装脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7664024/

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