2012-03-02 29 views
0

我剛開始使用蘋果腳本,我想製作一個提示用戶輸入URL的應用程序。在此之後,應用程序會在Safari的新選項卡中打開給定的URL。這是我的,但它不工作。想要在Safari的新選項卡中打開用戶生成的URL

tell me 
     activate 
     set s to display dialog "Which website do you want to open?" default answer "https://www." 
    end tell 
    tell application "System Events" 
     tell application "Safari" to activate 
     tell process "Safari" 
      click menu item "New Tab" of menu "File" of menu bar 1 
     end tell 
    end tell 

    tell application "Safari" 
     set URL of document 1 to "text returned of s" 
    end tell 

回答

1

通過封閉「文本返回S的」引號,你已經是一個字符串,而不是你想要使用記錄屬性 - 去掉引號將使其工作。您不必腳本化用戶界面以製作標籤,但該命令位於Safari的腳本字典中,例如:

tell me to activate 
set s to text returned of (display dialog "Which website do you want to open?" default answer "https://www.") 
tell application "Safari" 
    activate 
    tell window 1 
     set current tab to (make new tab) 
     set URL of current tab to s 
    end tell 
end tell