在AppleScript

时间:2018-06-15 19:27:00

标签: macos applescript backslash text-manipulation

我目前正在尝试创建一个AppleScript应用程序,该应用程序将从其内容"内容"文件夹到用户的桌面。我目前的代码是:

set theFile to path to me as string
set hfsme to theFile & "Contents:Folder"
set posixPath to POSIX path of hfsme

set contentfolder to posixPath
set AppleScript's text item delimiters to " "
set textItem to text items of contentfolder
set AppleScript's text item delimiters to "\\ "
set contentfolder to textItem as string
set AppleScript's text item delimiters to {""}

do shell script "cp -a " & contentfolder & " $HOME/Desktop"

但是,我在运行时收到以下错误:

" cp:/ Users / myusername / Desktop / Test Application.app/Contents/Folder:没有这样的文件或目录"

我认为这是因为我希望复制位置为:

/Users/myusername/Desktop/Test\ Application.app/Contents/Folder

但脚本无法在空间之前添加反斜杠,这是shell命令所需的。

我的问题是:如何用" \"替换变量中的空格? ?

P.S。在建议简单地将应用程序重命名为没有空格的名称之前,对我来说,拥有一个带空格的应用程序名称非常重要。 我也试过使用"复制"使用AppleScript命令但是无法使其工作,但我愿意接受建议! (请记住,我希望这个脚本能够在其他人的计算机上工作,这意味着我不能假设我已经知道用户的用户名。

提前感谢您的帮助!

亲切的问候,汤姆

1 个答案:

答案 0 :(得分:0)

只需添加look-controls,它就会以非常智能(可靠)的方式处理报价。

<a-entity camera look-controls="pointerLockEnabled: true"></a-camera>

如果quoted form of不支持set theFile to POSIX path of (path to me) set contentfolder to theFile & "Contents/Folder" do shell script "cp -a " & quoted form of contentfolder & " $HOME/Desktop" ,请写

do shell script
相关问题