如何在 运行 时将 App 移动到 Applications 文件夹?
How to move App to Applications folder when running it?
我想做的是,当用户从 Applications 文件夹外部运行该 App 时,会出现一个显示警告,询问他是否要将该 App 移动到 Applications 文件夹(如果该 App 不在该文件夹中)。
我尝试了以下方法:
tell application (path to frontmost application as text)
set myApp to path of document 1
set folderApplications to "/Applications" as POSIX file
set anyApp to "/Applications/My.app" as POSIX file
tell application "Finder"
if exists anyApp then
display alert "There is already an App with the same name in Applications Folder.
return
else
tell application "System Events"
move myApp to folderApplications
end tell
end if
end tell
end tell
错误:无法获取文档 1 的 «class FTPc»。(错误 -1728)
类似的方法可能对您有用。代码必须首先保存为名为 "myApp.app" 的应用程序才能正常运行。
property myName : "myApp.app"
set folderApplications to path to applications folder as text
set pathToMe to path to me as text
tell application "Finder"
set appExists to exists of alias (folderApplications & myName)
end tell
if not appExists then
beep 3
set moveApp to button returned of (display dialog ¬
"Would You Like To Move This App To The Applications Folder?" buttons {"No", "Yes"} ¬
default button 2 ¬
with title "Move This App?")
if moveApp is "Yes" then
tell application "Finder"
move alias pathToMe ¬
to alias folderApplications
end tell
end if
end if
-- the rest of your code
我想做的是,当用户从 Applications 文件夹外部运行该 App 时,会出现一个显示警告,询问他是否要将该 App 移动到 Applications 文件夹(如果该 App 不在该文件夹中)。 我尝试了以下方法:
tell application (path to frontmost application as text)
set myApp to path of document 1
set folderApplications to "/Applications" as POSIX file
set anyApp to "/Applications/My.app" as POSIX file
tell application "Finder"
if exists anyApp then
display alert "There is already an App with the same name in Applications Folder.
return
else
tell application "System Events"
move myApp to folderApplications
end tell
end if
end tell
end tell
错误:无法获取文档 1 的 «class FTPc»。(错误 -1728)
类似的方法可能对您有用。代码必须首先保存为名为 "myApp.app" 的应用程序才能正常运行。
property myName : "myApp.app"
set folderApplications to path to applications folder as text
set pathToMe to path to me as text
tell application "Finder"
set appExists to exists of alias (folderApplications & myName)
end tell
if not appExists then
beep 3
set moveApp to button returned of (display dialog ¬
"Would You Like To Move This App To The Applications Folder?" buttons {"No", "Yes"} ¬
default button 2 ¬
with title "Move This App?")
if moveApp is "Yes" then
tell application "Finder"
move alias pathToMe ¬
to alias folderApplications
end tell
end if
end if
-- the rest of your code