与X code。将AppleScriptObjC应用程序中嵌入一个bash shell脚本 [英] Embed a bash shell script in an AppleScriptObjC application with Xcode

查看:257
本文介绍了与X code。将AppleScriptObjC应用程序中嵌入一个bash shell脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图遵循<一的说明href=\"http://stackoverflow.com/questions/18362914/is-there-a-way-to-package-bash-shell-scripts-with-applescriptobjc-app-on-macosx\">this帖子但我未能达到理解如何一些海报说明工作。

I have attempted to follow the instructions on this post but I am falling short of understanding how some of the posters instructions work.

我希望能够打包以prewritten bash脚本的应用程序,然后执行它,但不从的步骤遵循4 开始。

I want to be able to package the app with a prewritten bash script and then execute it, but don't follow from Step 4 onwards.

帖子写道:

4。另外,在你的AppleScriptObjC脚本中,添加以下酌情:

    property pathToResources : "NSString"  -- works if added before script command

5。在适当的地方,还可以添加在你的AppleScriptObjC脚本如下:

    set yourScript to pathToResources & "/yourScriptFile.sh" 
    -- gives the complete unix path
    -- if needed, you can convert this to the Apple style path:
    set yourScriptPath to (((yourScript as text) as POSIX file) as alias)`

6。顺便说一句,你可以使用,然后打开读取文件

    tell application "Finder"
        open yourScriptPath
    end tell


问题:


  1. 在哪里添加一行:

  1. Where do I add the line:

property pathToResources : "NSString"


  • 我加入其中以下步骤,在哪里?

  • Do I add which of the following, and where?

    set yourScript to pathToResources & "/yourScriptFile.sh" 
    

    set yourScriptPath to (((yourScript as text) as POSIX file) as alias)
    


  • 这怎么可能执行该脚本本身呢?提顺便说一句,然后你可以用打开文件进行读只覆盖了苹果风格的路径,它不包括使用上述风格。

  • How is it possible to execute the script itself? The mention As an aside, you could then open the file for read using only covers the Apple style path, it does not cover using the aforementioned style.

    任何人都可以摆脱多一点光就这对我来说,或发布 AppDelegate.applescript 文件的静态副本,显示了如何所需的基本$ C楼主$ C被使用?我曾尝试他的方法,并期待在互联网在过去的3周无济于事。我不希望有转换所有我的code从的bash脚本到AppleScript的具体工具,因为这将需要大量的工作。


    Can anyone shed a bit more light on this for me, or post a static copy of a AppDelegate.applescript file that shows how the original poster required the base code to be used? I have tried his method and looked across the internet for the past 3 weeks to no avail. I don't want to have to convert all my code for specific tools from bash scripts into AppleScript, as this would take a lot of work.

    我只需要知道如何引用脚本文件在我的应用程序,这将驻留在应用程序,并用X包括(例如 myBashScript.sh ) code在编译时间。

    I only need to know how to reference to the script file (for example myBashScript.sh) in my app, which would reside in the application and be included by Xcode at time of compilation.

    推荐答案

    最后我把所有的信息一起,现在有一个解决方案。

    这考虑了以下事实:

    firstScript =变量,指向一个名为scriptNumberOne.sh结果脚本名称
    scriptNumberOne.sh =,我已经嵌入到我的应用程序脚本的运行结果
    _ ButtonHandlerRunScript =中的接收到的动作以x code结果
    pathToResources =指向我的应用程序的内部资源文件夹,不管变量的当前位置。

    firstScript = variable name that points to a script called scriptNumberOne.sh
    scriptNumberOne.sh = the script that I have embedded into my application to run
    ButtonHandlerRunScript_ = the name of the Received Action in Xcode
    pathToResources = variable that points to the internal Resources folder of my application, regardless of it's current location

    利用这些信息,下面是我AppleScriptObjC X code ++项目香草 AppDelegate.applescript 的副本:

    Using this information, below is a copy of a vanilla AppDelegate.applescript in my AppleScriptObjC Xcode project:

    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
    

    这篇关于与X code。将AppleScriptObjC应用程序中嵌入一个bash shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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