2017-01-27 4 views
0

これは、コマンドライン "osascript Export \ Library.scpt/Users/bryandunphy/Development/iTunesLibraryConsolidator testing.xml"を使用して、ターミナルからosascriptを実行するときに発生します。なぜこのApplescriptは "Export Library.scpt:execution error:システムイベントにエラーがあります:プロセス" i "(-1728)を取得できません"という原因ですか?

私の最後の(解決された)質問と同じスクリプトですが、今回は全部投稿します。

-- `menu_click`, by Jacob Rus, September 2006 
-- 
-- Accepts a list of form: `{"Finder", "View", "Arrange By", "Date"}` 
-- Execute the specified menu item. In this case, assuming the Finder 
-- is the active application, arranging the frontmost folder by date. 

on menuClick(mList) 
local appName, topMenu, r 

-- Validate our input 
if mList's length < 3 then error "Menu list is not long enough" 

-- Set these variables for clarity and brevity later on 
set {appName, topMenu} to (items 1 through 2 of mList) 
set r to (items 3 through (mList's length) of mList) 

-- This overly-long line calls the menu_recurse function with 
-- two arguments: r, and a reference to the top-level menu 
tell application "System Events" to my menuClickRecurse(r, ((process appName)'s ¬ 
    (menu bar 1)'s (menu bar item topMenu)'s (menu topMenu))) 
end menuClick 

on menuClickRecurse(mList, parentObject) 
    local f, r 

-- `f` = first item, `r` = rest of items 
set f to item 1 of mList 
if mList's length > 1 then set r to (items 2 through (mList's length) of mList) 

-- either actually click the menu item, or recurse again 
tell application "System Events" 
    if mList's length is 1 then 
     click parentObject's menu item f 
    else 
     my menuClickRecurse(r, (parentObject's (menu item f)'s (menu f))) 
    end if 
end tell 
end menuClickRecurse 

-- Created by Bryan Dunphy during January of 2017 
-- 
-- select the folder "directory" in Window "WinName" of Application "appName" and then clicks the default button if requested 
-- if WinName is "" then it uses the frontmost window (to allow for unnamed windows) 
-- REQUIRES "on handleDir" and "on findRoot" to work! 
-- ONLY call switchDir 
-- "createIt" is a boolean that will create any missing directories if it is set to "true". 
-- "selectDefault" is a boolean indicating whether or not to click the window's default button after selecting the specified directory 
-- returns "true" or "false" to indicate success. 
-- clicks "Cancel" button on failure 
-- Always returns "true" if "createIt" is set to "true" 
on switchDir(directory, winName, appName, createIt, selectDefault) 
    local dirs, delim 
    set delim to AppleScript's text item delimiters 
    set AppleScript's text item delimiters to "/" 
    set dirs to every text item of directory 
    tell application "System Events" to tell process appName to set frontmost to true 
    my findRoot(appName, winName) 
    repeat with dir in dirs 
     if not handleDir(dir, winName, createIt) then 
      tell application "System Events" to tell process appName to tell button "Cancel" to click 
      return false 
     end if 
    end repeat 
    if selectDefault then keystroke return 
    return true 
end switchDir 

on handleDir(dir, winName, appName, createIt) 
    local foundIt 
    foundIt = false 
    local ndx 
    if winName is not "" then 
     repeat with ndx from 1 to (count of window winName's list 1) 
      if window winName's list 1's item ndx's value is equal to dir then 
       select window winName's list 1's item ndx 
       foundIt = true 
       exit repeat 
      end if 
     end repeat 
    else 
     repeat with ndx from 1 to (count of front window's list 1) 
      if front window's list 1's item ndx's value is equal to dir then 
       select front window's list 1's item ndx 
       foundIt = true 
       exit repeat 
      end if 
     end repeat 
    end if 
    if not foundIt then 
     if createIt then 
      if winName is not "" then 
       tell application "System Events" to tell process appName to tell window winName 
        tell button "New Folder" 
         click 
         repeat until window "New Folder" exists 
          delay 0.5 
         end repeat 
         set value of text field 1 of window "New Folder" to dir 
         tell button "Create" to click 
         return my handleDir(dir) 
        end tell 
       end tell 
      else 
       tell application "System Events" to tell process appName to tell its front window 
        tell button "New Folder" 
         click 
         repeat until window "New Folder" exists 
          delay 0.5 
         end repeat 
         set value of text field 1 of window "New Folder" to dir 
         tell button "Create" to click 
         return my handleDir(dir) 
        end tell 
       end tell 
      end if 
     end if 
    else 
     return foundIt 
    end if 
end handleDir 

on findRoot(appName, winName) 
    local rootName 
    if winName is not "" then 
     tell application "System Events" to tell process appName to tell window winName 
      tell pop up button 1 
       click 
       repeat until menu 1 exists 
        delay 0.5 
       end repeat 
       local ndx 
       repeat with ndx from 1 to (count of menu 1) 
        if the title of menu 1's menu item ndx is "" then 
         set rootName to the title of menu 1's menu item (ndx - 1) 
         select (menu 1's menu item (ndx - 1)) 
         exit repeat 
        end if 
       end repeat 
      end tell 
     end tell 
    else 
     tell application "System Events" to tell process appName's front window 
      tell pop up button 1 
       click 
       repeat until menu 1 exists 
        delay 0.5 
       end repeat 
       local ndx 
       repeat with ndx from 1 to (count of menu 1) 
        if the title of menu 1's menu item ndx is "" then 
         set rootName to the title of menu 1's menu item (ndx - 1) 
         select (menu 1's menu item (ndx - 1)) 
         exit repeat 
        end if 
       end repeat 
      end tell 
     end tell 
    end if 
    return rootName 
end findRoot 

on run (clp) 
    if clp's length is not 2 then error "Incorrect Parameters" 
    local destination, libraryName 
    set destination to clp's item 1 
    set libraryName to clp's item 2 
    menuClick("iTunes", "File", "Library", "Export Library…") 
    set value of parentObject's text field "Save As:" to (libraryName and ".xml") 
    tell pop up button 1 of group 1 of window "New iTunes Library" of process iTunes of application "System Events" to click 
    repeat with ndx from 1 to (count of parentObject's menu 1) 
     if title of menu item ndx is "" then 
      select menu item (ndx - 1) 
      exit repeat 
     end if 
    end repeat 
    my switchDir(destination, "iTunes", "iTunes", true, false) 
    set the value of text field "Save As:" of window "iTunes" to (libraryName + ".xml") 
    tell button "Save" of window "iTunes" to click 
    return (destination and "/" and libraryName and ".xml") 
end run 

答えて

0

変更:

menuClick("iTunes", "File", "Library", "Export Library…") 

へ:

menuClick({"iTunes", "File", "Library", "Export Library…"}) 

のAppleScriptのエラー報告が(スターターのため、ノートレースバック)本当にひどいです、そしてosascriptはデバッグのためにスクリプトエディタよりもさらに悪くなります。 SEでスクリプトを実行すると、少なくともエラーが発生したスクリプト内の行が強調表示されます。それで手がかりが得られない場合は、logコマンドを追加してスクリプトの進捗状況を報告してください。 osascriptは、記録されたメッセージをstderrに書き込みます。 SEでは、ウィンドウの下部にある「ドキュメント」(表示/非表示)アイコンをクリックし、「メッセージ」を選択します。あなたの時間が$ 100以上の価値があるならば、スクリプトデバッガのコピーを手に入れてください。ブレークポイントを追加したり、スクリプトの実行中に変数を検査したり検査したりすることもできます。

+0

なぜ{}が必要なのですか?著者が提供したサンプルコードは私のコードと同じで、テストしたときに動作しましたか? –

+0

'{...}'はリスト値を示します。 'menuClick(mList)'ハンドラは、文字列のリストを唯一のパラメータとして期待しています。 4つのパラメータを渡していましたが、そのうちの最初の文字列(iTunesの文字列)が使用されています(ASは使用されていないパラメータを静かに無視します)。したがって、 'mList'の項目1を取得したときに、リストの最初の項目を取得する代わりに、文字列の最初の項目を取得します。この場合、文字「i」です。したがって、元のエラーメッセージ。そのすべては、はっきりと「ユーザーフレンドリな」言語でははるかに遠く、はるかに不明瞭で、役に立たず、不自由なものですが、それはAppleScriptです。 – foo

関連する問題