使用Xcode在AppleScriptObjC应用程序中嵌入bash shell脚本
我曾尝试按照上的说明进行操作,但我不了解一些海报说明是如何工作的 我希望能够使用预先编写的bash脚本打包应用程序,然后执行它,但不要从步骤4开始执行使用Xcode在AppleScriptObjC应用程序中嵌入bash shell脚本,xcode,bash,applescript,applescript-objc,Xcode,Bash,Applescript,Applescript Objc,我曾尝试按照上的说明进行操作,但我不了解一些海报说明是如何工作的 我希望能够使用预先编写的bash脚本打包应用程序,然后执行它,但不要从步骤4开始执行 帖子写道: 四,。此外,在AppleScriptObjC脚本中,在适当的位置添加以下内容: 五,。在适当的情况下,还可以在AppleScriptObjC脚本中添加以下内容: 六,。另一方面,您可以使用 问题: 在何处添加行: property pathToResources : "NSString" 我是否要添加以下哪项,以及在哪里添加
帖子写道: 四,。此外,在AppleScriptObjC脚本中,在适当的位置添加以下内容: 五,。在适当的情况下,还可以在AppleScriptObjC脚本中添加以下内容: 六,。另一方面,您可以使用
问题:
property pathToResources : "NSString"
set yourScript to pathToResources & "/yourScriptFile.sh"
或
有人能为我解释一下这一点吗,或者发布一个
AppDelegate.applescript
文件的静态副本,显示原始海报如何使用基本代码?在过去的3周里,我尝试了他的方法,并在互联网上查看了一遍,但都没有结果。我不想把我所有的特定工具代码从bash脚本转换成AppleScript,因为这需要很多工作
我只需要知道如何在我的应用程序中引用脚本文件(例如
myBashScript.sh
),它将驻留在应用程序中,并在编译时由Xcode包含。我认为您应该使用命令指向资源的路径
请参阅标准增补,资源路径
您可以通过将myVariableName设置为资源“myBashScript.sh”的路径进行设置,或者只使用该命令而不是您的属性,使其始终指向正确的位置(用户可以在运行时移动您的应用程序…lol)
补充:
我在AppleScript应用程序中就是这样做的:
on run_scriptfile(this_scriptfile)
try
set the script_file to path to resource this_scriptfile
return (run script script_file)
end try
return false
end run_scriptfile
每当我想运行捆绑在我的应用程序中的脚本时,我都会执行以下操作:
if my run_scriptfile("TestScript.scpt") is false then error number -128
run\u scriptfile(此脚本文件)
在一切正常时返回true
我把所有的信息汇集在一起,现在有了一个解决方案
这考虑到以下事实:
firstScript=指向名为scriptNumberOne.sh的脚本的变量名
scriptNumberOne.sh=已嵌入应用程序以运行的脚本
按钮handlerrunscript \=在Xcode中的名称
pathToResources=指向我的应用程序的内部资源文件夹的变量,无论其当前位置如何
使用这些信息,下面是我的AppleScriptObjC Xcode项目中一个香草AppDelegate.applescript
的副本:
script AppDelegate
property parent : class "NSObject"
property pathToResources : "NSString"
on applicationWillFinishLaunching_(aNotification)
set pathToResources to (current application's class "NSBundle"'s mainBundle()'s resourcePath()) as string
end applicationWillFinishLaunching_
on ButtonHandlerRunScript_(sender)
set firstScript to pathToResources & "/scriptNumberOne.sh"
do shell script firstScript
end ButtonHandlerRunScript_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script
你能给我举个例子吗?这是一个空白应用程序的粘贴箱:打开AppleScript编辑器,按shift-command-l查看库,打开“标准添加”,搜索“资源路径”。阅读这些信息。你所说的是什么意思?或者只是使用命令而不是属性?顺便说一句:我使用AppleScript Editor创建了我的应用程序,所以这里可能有所不同。但你会看到它是否有效。
set yourScriptPath to (((yourScript as text) as POSIX file) as alias)
on run_scriptfile(this_scriptfile)
try
set the script_file to path to resource this_scriptfile
return (run script script_file)
end try
return false
end run_scriptfile
if my run_scriptfile("TestScript.scpt") is false then error number -128
script AppDelegate
property parent : class "NSObject"
property pathToResources : "NSString"
on applicationWillFinishLaunching_(aNotification)
set pathToResources to (current application's class "NSBundle"'s mainBundle()'s resourcePath()) as string
end applicationWillFinishLaunching_
on ButtonHandlerRunScript_(sender)
set firstScript to pathToResources & "/scriptNumberOne.sh"
do shell script firstScript
end ButtonHandlerRunScript_
on applicationShouldTerminate_(sender)
-- Insert code here to do any housekeeping before your application quits
return current application's NSTerminateNow
end applicationShouldTerminate_
end script