Как переместить приложение в папку «Приложения» при его запуске? - PullRequest
0 голосов
/ 25 марта 2020

Я пытаюсь сделать так, чтобы, когда пользователь запускает приложение из-за пределов папки «Приложения», на экране появляется предупреждение, спрашивающее, хочет ли он переместить приложение в папку «Приложения», если приложение еще не существует. Я попробовал следующее:

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

ОШИБКА: не удается получить «класс FTPc» документа 1. (ошибка -1728)

1 Ответ

1 голос
/ 26 марта 2020

Нечто подобное может работать на вас. Код должен быть сначала сохранен как приложение с именем «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
...