종료 후 변수를 저장해야하는 매우 복잡한 AppleScript 응용 프로그램을 작성하고 있습니다. 따라서 변수가 실행 중일 때 변수를 설정하고 닫은 다음 다시 열면 변수가 동일하게 유지됩니다.AppleScript에서 종료하고 다시 연 후 변수를 저장하는 방법은 무엇입니까?
이 스크립트는 처음 실행시 설정 메뉴를 표시합니다. 그런 다음 응용 프로그램을 닫은 후에 환경 설정을 저장하십시오. 기타 기술적 설명 :
setup (실행)을 시작하면 isSetup이 false인지 확인하고 setup() 함수로 이동합니다. setup() 함수는 환경 설정을 지정하고 isSetup을 true로 설정합니다. 종료하고 응용 프로그램을 다시 열면 setup() 함수가 다시 실행됩니다.
나는 전체 스크립트를 복사하여 붙여 넣기로되어있는 것은 아니지만 스크립트없이 복제본을 찾을 수는 없다는 것을 알고있다. 여기에 있습니다 :
--AppleScript: menu bar script -- Created 2017-03-03 by Takaaki Naganoya adapted by ----
--2017 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
--http://piyocast.com/as/archives/4502
property aStatusItem : missing value
global theToggle
global theMenuTitle
global aTag
global aTitle
global isSetup
global usrName
global usrPass
global usrProtocol
property usrName : missing value
property usrPass : missing value
property isSetup : false
property usrProtocol : missing value
on run
if isSetup is false then
setup()
else
set theToggle to "Connect"
set theMenuTitle to "Server Helper"
init()
end if
end run
on init()
set aList to {theToggle, "Preferences", "Change Password", "", "Quit"}
set aStatusItem to current application's NSStatusBar's systemStatusBar()'s statusItemWithLength:(current application's NSVariableStatusItemLength)
aStatusItem's setTitle:theMenuTitle
aStatusItem's setHighlightMode:true
aStatusItem's setMenu:(createMenu(aList) of me)
end init
on createMenu(aList)
set aMenu to current application's NSMenu's alloc()'s init()
set aCount to 1
repeat with i in aList
set j to contents of i
if j is not equal to "" then
set aMenuItem to (current application's NSMenuItem's alloc()'s initWithTitle:j action:"actionHandler:" keyEquivalent:"")
else
set aMenuItem to (current application's NSMenuItem's separatorItem())
end if
(aMenuItem's setTarget:me)
(aMenuItem's setTag:aCount)
(aMenu's addItem:aMenuItem)
if j is not equal to "" then
set aCount to aCount + 1
end if
end repeat
return aMenu
end createMenu
on setup()
display dialog " Welcome to the Server setup Utility.
To Begin click " & quote & "Continue" & quote & " below." buttons {"Cancel", "Continue"} default button 2
set theButton to the button returned of the result
if theButton is "Continue" then
display dialog "Please enter your " & quote & "Username" & quote & " for the Brown Server." default answer "Username" buttons {"Continue"} default button 1
set usrName to the text returned of the result
display dialog "Please enter your " & quote & "Password" & quote & " for the Brown Server." default answer "" buttons {"Continue"} default button 1 with hidden answer
set usrPass to the text returned of the result
set listDeProtocols to {"AFP", "SMB", "WebDav", "FTP"}
set usrProtocol to (choose from list listDeProtocols with prompt "Choose Your Prefered Protocol. AFP is recomended. If AFP does not work try SMB. All others are not supported at this time")
set isSetup to true
postSet()
end if
end setup
on postSet()
if isSetup is false then
setup()
else
set theToggle to "Connect"
set theMenuTitle to "Server Helper"
init()
end if
end postSet
on changePref()
end changePref
on pref()
set length1 to the length of usrPass
set p1 to ""
set p2 to ""
repeat length1 times
set p1 to "•"
set p2 to p1 & p2
end repeat
display dialog "These are your following preferences. Click the " & quote & "Change" & quote & " to change.
Username: " & usrName & "
Password: " & p2 & "
Prefered Protocol: " & usrProtocol buttons {"Back", "Change"}
set theButton to the button returned of the result
if theButton is "Change" then
changePref()
end if
end pref
on actionHandler:sender
set aTag to tag of sender as integer
set aTitle to title of sender as string
if aTitle is not equal to "Quit" then
current application's NSStatusBar's systemStatusBar()'s removeStatusItem:aStatusItem
if aTitle is "Connect" then
set theToggle to "Disconnect"
init()
end if
if aTitle is "Disconnect" then
current application's NSStatusBar's systemStatusBar()'s removeStatusItem:aStatusItem
set theToggle to "Connect"
init()
end if
if aTitle is "Preferences" then
pref()
end if
if aTitle is "Change Password" then
changePass()
end if
else
current application's NSStatusBar's systemStatusBar()'s removeStatusItem:aStatusItem
end if
end actionHandler:
필자에게 적합합니다. 사용중인 OS X/macOS의 버전은 무엇입니까? – user3439894
높은 시에라. 응용 프로그램으로 내보내고 작동하는지보십시오. – Josh
실행 중에 다른 값으로 설정된 AppleScript 스크립트/응용 프로그램을 컴파일하거나 저장하면 원래 값으로 다시 설정된다는 점을 알고 있습니다. 이 예제에서'missing value', 맞습니까? 그것은 macOS High Sierra에서도 마찬가지입니다. – user3439894