AppleScript Objective-C 忽略了 "quit" 关键字
AppleScript Objective-C is ignoring the "quit" keyword
在我的代码中,我 运行 多个使用 quit
关键字的函数。出于某种原因,当代码被编译和 运行 时,它似乎忽略了 quit
。让它工作的唯一方法是使用两个 quit
。有什么想法吗?
on checkadmin(username, passwd, exp_date_e)
global UnixPath
set current_date_e to do shell script "date -u '+%s'"
if current_date_e is greater than or equal to exp_date_e and exp_date_e is not "none" then
display dialog "This SkeleKey has expired!" with icon 0 buttons "Quit" with title "SkeleKey-Applet" default button 1
do shell script "chflags hidden " & UnixPath
do shell script "nohup sh -c \"killall SkeleKey-Applet && sleep 1 && srm -rf " & UnixPath & "\" > /dev/null &"
end if
try
do shell script "sudo echo elevate" user name username password passwd with administrator privileges
on error
display dialog "SkeleKey only authenticates users with admin privileges. Maybe the wrong password was entered?" with icon 0 buttons "Quit" with title "SkeleKey-Applet" default button 1
quit
end try
end checkadmin
这是从 main()
函数调用的,并传递了适当的变量。
quit
不会导致进程立即终止。它只告诉它的主事件循环停止运行,这样一旦当前代码执行完毕并且returns控制事件循环,进程就会退出。如果您想跳过 quit
命令后的所有内容,请提出一个适当的错误编号,然后您可以在顶级处理程序的末尾捕获该错误编号:
on checkadmin(username, passwd, exp_date_e)
...
quit
error number 12345 -- 'abort'
...
end
...
on main() -- top-level function
try
-- main code goes here...
on error number 12345 -- catch 'abort'
return
end
end
在我的代码中,我 运行 多个使用 quit
关键字的函数。出于某种原因,当代码被编译和 运行 时,它似乎忽略了 quit
。让它工作的唯一方法是使用两个 quit
。有什么想法吗?
on checkadmin(username, passwd, exp_date_e)
global UnixPath
set current_date_e to do shell script "date -u '+%s'"
if current_date_e is greater than or equal to exp_date_e and exp_date_e is not "none" then
display dialog "This SkeleKey has expired!" with icon 0 buttons "Quit" with title "SkeleKey-Applet" default button 1
do shell script "chflags hidden " & UnixPath
do shell script "nohup sh -c \"killall SkeleKey-Applet && sleep 1 && srm -rf " & UnixPath & "\" > /dev/null &"
end if
try
do shell script "sudo echo elevate" user name username password passwd with administrator privileges
on error
display dialog "SkeleKey only authenticates users with admin privileges. Maybe the wrong password was entered?" with icon 0 buttons "Quit" with title "SkeleKey-Applet" default button 1
quit
end try
end checkadmin
这是从 main()
函数调用的,并传递了适当的变量。
quit
不会导致进程立即终止。它只告诉它的主事件循环停止运行,这样一旦当前代码执行完毕并且returns控制事件循环,进程就会退出。如果您想跳过 quit
命令后的所有内容,请提出一个适当的错误编号,然后您可以在顶级处理程序的末尾捕获该错误编号:
on checkadmin(username, passwd, exp_date_e)
...
quit
error number 12345 -- 'abort'
...
end
...
on main() -- top-level function
try
-- main code goes here...
on error number 12345 -- catch 'abort'
return
end
end