2016-08-25 2 views
0

txtファイル(IPアドレスのリスト)の内容を読み込み、シェルスクリプトループで使用するためのリストを作成しようとしています。 "set POSIX file file path"の段落への切り替えを設定し、私は再構築が必要だと思っていますが、AppleScriptを知っていてObjCにほとんど入っていないので、私には困惑してしまいました....ApplescriptObjC - Finderからplain txtファイルの内容を読み込んでリストを作成する

I本当に最初の3行を変更するファイルパスを設定するにはファイルを選択したいが、私は同じエラーが発生します。

on theButtonChooseFile_(sender) 
    set x to (system info) 
    set theuser to short user name of x 
    set filepath to "/Users/" & theuser & "/Desktop/switches.txt" as string -- Define path to file 
    set listOfSwitches to {} 
    set Switches to paragraphs of (read POSIX file filepath) 
    repeat with nextLine in Switches 
     if length of nextLine is greater than 0 then 
      copy nextLine to the end of listOfSwitches 
     end if 
    end repeat 
end theButtonChooseFile_ 

エラー:

2016-08-25 08:13:37.655 Cisco Configurator[67884:4593159] *** -[AppDelegate theButtonChooseFile:]: Can’t make current application into type file. (error -1700)

答えて

0

AppleScriptのreadコマンドはまた、POSIXパスを受け入れ、あなたは、単に

path to desktop 

全体ハンドラで、現在のユーザーのデスクトップフォルダへのパスを取得することができますこのように書くことができます

on theButtonChooseFile_(sender) 
    set desktopFolder to POSIX path of (path to desktop) 
    set filepath to desktopFolder & "switches.txt" 
    set Switches to paragraphs of (read filepath) 

    set listOfSwitches to {} 
    repeat with nextLine in Switches 
     if length of nextLine is greater than 0 then 
      copy nextLine to the end of listOfSwitches 
     end if 
    end repeat 
end theButtonChooseFile_ 

しかし、listOfSwitchesのハンドラにしかアクセスできません。

+0

ありがとうございました。 lisofSwitchesが分離されていることは大丈夫です。それを必要とするものはすべてそのハンドラ内にあります。私は、ユーザーがファイルを選択できるようにしたい場合でもパスとファイルを結合するためにあなたのロジックを使用することができると思う、私はそれらが含まれているフォルダを選択し、setファイルパスを使用して完全なパスを構築することができます。本当の答えはNSStringの中にあると思いますが、私はまだObjectiveCに精通していません。再度、感謝します!!!! –

+0

'choose folder'を使ってAppleScriptObjレベルを必要としないフォルダを選択した場合、' NSOpenPanel'を使うとFoundationオブジェクトがあり、 'NSString'を' textとして '強制する必要がありますAppleScriptレベルで使用してください。 – vadian

関連する問題