在ITerm2中运行shell命令,完成后不关闭选项卡

时间:2016-10-24 15:04:57

标签: shell iterm2 iterm

可能是一个小错误的语法问题,但我找不到ITerm2 documentation中的解决方案。我想创建一个打开ITerm窗口的AppleScript,其中有三个选项卡,每个选项卡运行各种shell命令(ls,cd,echo等),其中选项卡在运行这些命令后保持打开状态。打开标签部分工作正常,但似乎一旦命令运行,标签关闭(如果我不提供任何命令,标签将保持打开状态。)对于我的脚本:

tell application "iTerm2"
  create window with default profile
  tell current window
     create tab with default profile command "echo abc"
     create tab with default profile
  end tell
end tell

而不是“echo abc”我应该放在那里,所以echo命令将在选项卡中运行,但是留给我一个光标让我输入更多命令而不是之后立即关闭的选项卡?

2 个答案:

答案 0 :(得分:0)

不使用create tab ... command,而是使用单独的write text命令。例如,这是我用来打开终端到特定目录的脚本:

tell application "iTerm"
  create window with default profile
  tell current session of current window
    write text "cd " & directory & "; clear"
  end tell
end tell

答案 1 :(得分:0)

使用"写文字"由whereswalden建议我解决了以下问题,效果很好:

add_action( 'rest_api_init', 'wp_rest_insert_tag_links' );

function wp_rest_insert_tag_links(){

    register_rest_field( 'post',
        'post_categories',
        array(
            'get_callback'    => 'wp_rest_get_categories_links',
            'update_callback' => null,
            'schema'          => null,
        )
    );
    register_rest_field( 'post',
        'post_tags',
        array(
            'get_callback'    => 'wp_rest_get_tags_links',
            'update_callback' => null,
            'schema'          => null,
        )
    );
}

function wp_rest_get_categories_links($post){
    $post_categories = array();
    $categories = wp_get_post_terms( $post['id'], 'category', array('fields'=>'all') );

foreach ($categories as $term) {
    $term_link = get_term_link($term);
    if ( is_wp_error( $term_link ) ) {
        continue;
    }
    $post_categories[] = array('term_id'=>$term->term_id, 'name'=>$term->name, 'link'=>$term_link);
}
    return $post_categories;

}
function wp_rest_get_tags_links($post){
    $post_tags = array();
    $tags = wp_get_post_terms( $post['id'], 'post_tag', array('fields'=>'all') );
    foreach ($tags as $term) {
        $term_link = get_term_link($term);
        if ( is_wp_error( $term_link ) ) {
            continue;
        }
        $post_tags[] = array('term_id'=>$term->term_id, 'name'=>$term->name, 'link'=>$term_link);
    }
    return $post_tags;
}