Set command in the middle of do shell script

痞子三分冷 提交于 2019-12-25 04:57:12

问题


I have been attempting to make a simple application that copies a selected file to a predetermined directory, only the variable does not work when set in a shell script. I was wondering if there is a way to phrase the copy or move command to allow it to take effect. The script is below.

set filepath to POSIX path of (choose file with prompt "Chose your file")
delay
do shell script "cp " & filepath & " ~/Library/Application Support/"

回答1:


It does not work because space characters in paths must be escaped, the most reliable way is to use quoted form of.

path to application support folder from user domain is the relative path to the current user's application support folder.

set applicationSupportFolder to POSIX path of (path to application support folder from user domain)
set filepath to POSIX path of (choose file with prompt "Chose your file")
do shell script "cp " & quoted form of filepath & space & quoted form of applicationSupportFolder


来源:https://stackoverflow.com/questions/42130717/set-command-in-the-middle-of-do-shell-script

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!