2017-08-30 17 views
-1

我一直在尝试通过编写几行简单的代码来探索AppleScript。我试着写了一小段,让我可以访问可用的Wi-Fi列表,并将密码输入到所述的Wi-Fi。AppleScript Wi-Fi连接器

到目前为止,我已经到了可以识别Wi-Fi的地步,但不允许我将Wi-Fi制作成字符串。我已经编写了从列表中选择Wi-Fi的代码,但我无法弄清楚如何将Wi-Fi列入清单。

任何人都可以帮助我解决这个问题吗?

display dialog "Wifi Selector © Afnaan Qureshi" 
set main to display dialog " ." buttons {"Quit", "Enter Password"} 
if main = {button returned:"Enter Password"} or trueaftermain = "1" then 


    set results to paragraphs 2 thru -1 of (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s | sed -nE 's/[ ]*(.*) [a-z0-9]{2}:[a-z0-9]{2}:.+/\\1/p'") 
    set my_list to results 
    set AppleScript's text item delimiters to ", " 
    set list_2_string to my_list as text 
    set main to display dialog my_list 
    set wpass to choose from list {my_list} with title "Pick The Wifi" with prompt "Choose WPA2" OK button name "Choose" cancel button name "Cancel" default items {"quit"} 
end if 
+0

当我试图调试不适合你的代码时,我建议你看看[如何创建一个最小,完整和可验证的示例](https://stackoverflow.com/help/mcve)。 – user3439894

回答

0

您的代码太复杂了。

results已经是您期待的列表。

set results to paragraphs of (do shell script "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport -s | sed -nE 's/[ ]*(.*) [a-z0-9]{2}:[a-z0-9]{2}:.+/\\1/p'") 
set wpass to choose from list results with title "Pick The Wifi" with prompt "Choose WPA2" OK button name "Choose" 

注意wpass也是一个列表,或者false如果用户按下取消

如果您正在使用text item delimiters确保稍后重置分隔符,以避免意外的行为。