从传递的AppleScript多个参数终端命令脚本 [英] Passing Multiple Parameters from Applescript to Terminal Command Script
问题描述
我一直在试图找出如何从一个AppleScript将多个参数传递到终端命令脚本。例如运行终端命令文件时,您可以以编程方式接收参数,像这样:
I have been trying to figure out how to pass multiple parameters from an Applescript to a Terminal Command Script. For example when running a terminal command file you are able to receive parameters programatically like so:
#!/bin/bash
var=$1
var=$2
该AppleScript的code,我一直在使用低于供参考:
The Applescript Code that I have been working with is below for reference:
tell application "System Events" to set app_directory to POSIX path of (container of (path to me))
set thisFile to "Dev"
set testTarget to "/Users/lab/Desktop/TestTarget/"
do shell script "/Users/lab/Desktop/TempRoot/mycommand.command " & thisFile & testTarget with administrator privileges
在哪里,我认为我已经错的是第二个参数的输入。当我只有一个参数,它通过就好了:
Where I think I have gone wrong is the input of the second parameter. When I only had one parameter it went through just fine:
do shell script "/path/to/command/mycommand.command" &var with administrative privileges
我很好奇,什么正确的语法将是传递这个第二个参数。如果任何人有任何建议,请让我知道!此外,如果你需要更多的信息,我会很乐意提供它!
I am curious as to what the correct syntax would be for passing in this second parameter. If anybody has any suggestions please let me know! Also if you need more information I would be happy to provide it!
推荐答案
您只需要你的论点之间添加一个空格。眼下,有 thisFile
和 testTarget
之间添加任何空间。您的命令看起来是这样的:
You just need to add a space between your arguments. Right now, there is no space being added between thisFile
and testTarget
. Your command looks like this:
/Users/lab/Desktop/TempRoot/mycommand.command Dev/Users/lab/Desktop/TestTarget/
您的shell脚本行更改为:
Change your shell script line to:
do shell script "/Users/lab/Desktop/TempRoot/mycommand.command " & thisFile & space & testTarget with administrator privileges
东西,我建立一个脚本,以确保我的shell命令运行之前正确的,当有帮助。因此,而不是直接构建它,存储命令在一个变量,并记录它。后来,替换为做shell脚本
命令日志声明。
set shellScript to "/Users/lab/Desktop/TempRoot/mycommand.command " & thisFile & space & testTarget with administrator privileges
log shellScript
-- do shell script shellScript
这篇关于从传递的AppleScript多个参数终端命令脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!