1

私が取り組んでいるものの非常に簡単なセクションをスクリプト化するのに問題があります (私がそうなると思っていました)。基本的には、特定のアプリケーションでファイルを開くように Finder に指示したいと考えています。シンプルですね。私が読んだことから、私は使用できるはずです:

tell application "Finder"
    open "the_file" using "the_application"
end tell

問題は、Finder がアプリケーションを見つけるのに一苦労しているように見えることです。次のコードを使用すると:

set webArcExtract to POSIX file (do shell script "mdfind 'WebArchive Folderizer.app' -onlyin '/Applications/'") as string #Find the Web Archive Extraction Program

tell application "Finder" #Temporary path to save the web archive
    set tempPath to ((home as string) & "temp:")
end tell

tell application "Fake" #Magic that saves a webpage as a webarchive
    load URL "www.google.com"
    delay 3
    capture web page as Web Archive saving in tempPath & "arc.webarchive"
end tell

tell application "Finder" #Open the arc.webarchive file saved in the tempPath with the WebArchive Folderizer application
    open tempPath & "arc.webarchive" using webArcExtract
end tell

変数の値は次のとおりです。

tempPath: "OSX_Data:Users:user:" webArcExtract: "OSX:Applications:Utilities:WebArchive Folderizer.app"

コードを実行しようとしたときに発生するエラーは、webArcExtract 行を使用して、開いている tempPath & "arc.webarchive"で発生します。「アプリケーションが見つかりません」というメッセージが Finder からポップアップ表示されます。

私はこれに本当に困惑しています。私はパスが正しいことを知っており、アプリケーションがこの方法でファイルを開くことができることを知っています. Finder を使用して、開こうとしている arc.webarchive ファイルに移動し、ファイルを右クリックして、[開く] > [WebArchive Folderizer] を選択すると、完全に機能します。

助言がありますか?

4

1 に答える 1

3

ここにいくつかの提案があります。1) アプリケーションへのパスを取得する簡単な方法は、applescript の「path to」コマンドを使用するだけなので、このようなものが機能するはずです...

set theFile to (path to desktop as text) & "a.txt"
set appPath to path to application "TextWrangler"
tell application "Finder" to open file theFile using appPath

2) tempPath に Finder は必要ありません。ここでも「パスへのパス」を使用してください...

set tempPath to (path to home folder as text) & "temp:"

3) 最後に、ここでファイル指定子が必要なので、#1 で行ったように、ファイル パスの前にキーワード「file」を追加します...

tell application "Finder"
    open file (tempPath & "arc.webarchive") using webArcExtract
end tell

それが役立つことを願っています。

于 2011-04-26T22:47:53.313 に答える