如何从AppleScript的/的Automator / Shell脚本自动化的新的X code创建目标 [英] How to automate creation of new XCode targets from Applescript/Automator/Shell Script

查看:428
本文介绍了如何从AppleScript的/的Automator / Shell脚本自动化的新的X code创建目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在研究一种方法来自动添加新目标,以我的X code项目的过程。一个目标已经被添加到倍数x code项目,并在不同的项目中每个目标需要添加相同的源文件相同的组存储在X code项目的源代码文件和相同的构建设置。手动执行此操作可能需要一段时间,是很容易出现人为错误,我得相当频繁做这个任务。我已经写了一个脚本来生成新的源文件,将它们复制到系统文件夹,用新信息等编辑源文件,但现在我需要在X code部分自动化。

这总结我希望我的自动化程度达到什么:

在/this/path/project.x$c$cproj

打开一个X code项目

复制现有的目标并将其重命名

编辑的新目标生成设置

添加组到源和资源部分,然后将其重命名

源文件添加到组,将文件添加到新的目标

关闭X code

理想我想这从我的Bourne shell脚本运行的,我知道你可以从那里发射的Automator工作流。我不知道,最好的办法是实现这虽然,任何想法是什么?在此先感谢: - )


解决方案

让我跟这个剧本开始(对于x code 4.2.1),


  • 在/this/path/project.x$c$cproj打开一个X code项目(完成)

  • 复制现有的目标并将其重命名(未实现)

  • 编辑的新目标生成设置(完成)

  • 添加一组到源和资源部分,然后将其重命名(完成)

  • 源文件添加到组,将文件添加到新的目标(部分)

  • 关闭X code(完成)


  

!的/ usr / bin中/ osascript

 #参考:AppleScript的编辑器 - >文件 - >开放目录...  - > X $ C $Ç4.2.1#http://vgable.com/blog/2009/04/24/how-to-check-if-an-application-is-running-with-applescript/
在ApplicationIsRunning(的appName)
    告诉应用程序系统事件,设置为appNameIsRunning存在(工艺,其中名称是的appName)
    返回appNameIsRunning
结束ApplicationIsRunning如果没有ApplicationIsRunning(X code),那么
    日志(启动X $ C $ç...)
    启动应用IDcom.apple.dt.X code
    延迟5
其他
    日志(X code已经运行...)
万一设置project_path为/PATH/TO/YOUR_PROJECT.x$c$cproj
日志(AMP在打开一个X code工程; project_path)设置_project_name(做shell脚本回声$(基本名称与&&project_path安培;)| sed的-e'S / .X codeproj //')
日志(PROJECT_NAME设置为&安培; _project_name)_target_name设为YOUR_TARGET告诉应用程序IDcom.apple.dt.X code
    设置_project_file为(POSIX文件project_path为化名)
    开放_project_file
    #加载文件设定路径path_to_project显示是
    集_workspace到活动工作区文件
    设置_project为(他的名字= _project_name _workspace的项目)的第一项
    设置为_target的(他的名字= _target_name _project的目标)第一项    #因为这将无法工作,无法诉诸事件对系统事件
    #复制_target具有属性{名称:_target_name&放大器; _克隆}
    #使新建立的配置数据建立与性能{名_target配置:_target_name&放大器; _克隆}
    # 启用    日志(编辑的新目标生成设置)
    集_build_configuration到的第一个项目(建设名字_target的配置=调试)
    设置_build_configuration的PRODUCT_NAME构建的设定值设定为KeySING    #http://lists.apple.com/archives/x$c$c-users//2008/Feb/msg00497.html
    日志(添加组到源和资源部分,然后将其重命名)
    设置_new_group_name为groupX
    告诉_project根组
        设置_groups到(让他的名字组= _new_group_name)
        如果(_groups的长度)= 0,那么
            设置_new_group做出新组的属性{名称:_new_group_name,路径为:_new_group_name,路径类型:相对组}
        其他
            设置_new_group为_groups的第一项
        万一        日志(源文件添加到组,将文件添加到新的目标)
        告诉_new_group
            设置_new_file_name为whatever.h
            设置_new_files得到(文件引用他的名字= _new_file_name)
            如果(_new_files的长度)= 0,那么
                #X $ C $Ç崩溃
                #使与性能的新文件引用¬
                #{名字:_new_file_name,文件编码:UTF8,路径类型:相对组,¬
                #路径:_new_file_name}
            万一
        告诉结束
    告诉结束    日志(关闭X code)
    放弃告诉结束


I am currently working on a way to automate the process of adding new targets to my XCode projects. One target has to be added to multiple XCode projects and each target in the different project needs the same source files to be added, same groups to store the source files in the XCode project, and the same build settings. Doing this manually can take a while and is very prone to human error, and I have to do this task fairly often. I have already written a script to generate new source files, copy them to system folders, edit source files with new information etc, but now I need to automate the XCode part.

This sums up what I want my automation to achieve:

Open an XCode project at /this/path/project.xcodeproj

Duplicate an existing target and rename it

Edit the Build Settings of the new target

Add a group to the Source and Resources section, then rename them

Add source files to the groups, and add the file to the new Target

Close XCode

Ideally I want this to run from my Bourne Shell script, I know you can launch automator workflows from there. I'm not sure what the best approach is to achieving this though, any ideas? Thanks in advance :-)

解决方案

let me start with this script (for Xcode 4.2.1),

  • Open an XCode project at /this/path/project.xcodeproj (done)
  • Duplicate an existing target and rename it (not implemented)
  • Edit the Build Settings of the new target (done)
  • Add a group to the Source and Resources section, then rename them (done)
  • Add source files to the groups, and add the file to the new Target(partially)
  • Close XCode (done)

!/usr/bin/osascript

# Reference: AppleScript Editor -> File -> Open Directory ... -> Xcode 4.2.1

# http://vgable.com/blog/2009/04/24/how-to-check-if-an-application-is-running-with-applescript/
on ApplicationIsRunning(appName)
    tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
    return appNameIsRunning
end ApplicationIsRunning

if not ApplicationIsRunning("Xcode") then
    log ("Launching Xcode ...")
    launch application id "com.apple.dt.Xcode"
    delay 5
else
    log("Xcode is already running ...")
end if

set project_path to "/PATH/TO/YOUR_PROJECT.xcodeproj"
log ("Open an XCode project at " & project_path)

set _project_name to (do shell script "echo $(basename " & project_path & ") | sed -e 's/.xcodeproj//'")
log ("project_name set to " & _project_name)

set _target_name to "YOUR_TARGET"

tell application id "com.apple.dt.Xcode"
    set _project_file to (POSIX file project_path as alias)
    open _project_file
    # load documentation set with path path_to_project display yes
    set _workspace to active workspace document
    set _project to first item of (projects of _workspace whose name = _project_name)
    set _target to first item of (targets of _project whose name = _target_name)

    # as this won't work, cannot event resort to system event
    # duplicate _target with properties {name:_target_name & "_clone"}
    # make new build configuration with data build configurations of _target with properties {name:_target_name & "_clone"}
    # activate

    log ("Edit the Build Settings of the new target")
    set _build_configuration to first item of (build configurations of _target whose name = "Debug")
    set value of build setting "PRODUCT_NAME" of _build_configuration to "KeySING"

    # http://lists.apple.com/archives/xcode-users//2008/Feb/msg00497.html
    log ("Add a group to the Source and Resources section, then rename them")
    set _new_group_name to "groupX"
    tell root group of _project
        set _groups to (get groups whose name = _new_group_name)
        if (length of _groups) = 0 then
            set _new_group to make new group with properties {name:_new_group_name, path:_new_group_name, path type:group relative}
        else
            set _new_group to first item of _groups
        end if

        log ("Add source files to the groups, and add the file to the new Target")
        tell _new_group
            set _new_file_name to "whatever.h"
            set _new_files to get (file references whose name = _new_file_name)
            if (length of _new_files) = 0 then
                # Xcode crashes
                # make new file reference with properties ¬
                #     {name:_new_file_name, file encoding:utf8, path type:group relative,¬
                #      path:_new_file_name}
            end if
        end tell
    end tell

    log ("Close XCode")
    quit

end tell

这篇关于如何从AppleScript的/的Automator / Shell脚本自动化的新的X code创建目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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