0

Chrome でアクティブなドキュメントを開く textwrangler の Applescript を作成しようとしています。現時点でのスクリプトは次のようになります。

tell application "TextWrangler" to set theFile to file of document 1
tell application "Finder" to open theFile using (path to application "Google Chrome")

絶対パス「Applications/MAMP/www/index.php」を持つファイルで作業しているとしましょう。スクリプトは、ブラウザーでそのファイルを「file:// localhost/Applications/MAMP/www/index.php」として開き、php コードを表示します。

これの代わりに、'file:// localhost/Applications/MAMP/' を実際のサイトを示す 'http:// localhost/' に置き換えるスクリプトが必要です。

私はオンラインで見つけたものをたくさん試しましたが、これを達成するにはApplescriptの経験が少なすぎます.

4

3 に答える 3

0

これはどうですか、Chaseのリードに従って、javascriptを使用して文字列の置換を行います。

property delim : "MAMP" -- where to break the path and prepend localhost to

tell application "TextWrangler" to set theFile to file of document 1

tell application "Finder" to set p to the POSIX path of theFile -- convert it into a Unix path first

tell application "Google Chrome" to execute front window's active tab javascript ("pth='" & p & "';window.open('http://localhost'+ pth.split('" & delim & "').pop());")

多言語連結と文字列区切りでコードが読みにくくなりますが、動作するはずです。

于 2013-08-10T04:38:38.810 に答える
0

ここにいくつかの異なるオプションがあります..

1 つ目は、開きたいファイルがルート localhost ディレクトリにあることを前提としています。このスクリプトは、Safari に URL を開いてパスにファイル名を追加するように指示します。

このを初めて実行するときは、Mac アクセシビリティを認証して、Finder が必要なアクションを完了できるようにする必要がある場合があります。

try
    tell application "Finder" to set filePath to name of item 1 of (get selection)
        set the clipboard to filePath

        set localhost to "http://localhost/"

        tell application "Safari"
            activate
            tell application "System Events"
                tell process "Safari"
                    click menu item "New Tab" of menu "File" of menu bar 1

                end tell
            end tell
            set theURL to localhost & filePath
            set URL of document 1 to theURL
        end tell
    end tell
end try

別のオプションは、選択したファイルの POSIX パスをコピーし、Safari でローカル パスを開くことです。

try
    set filePath to {}
    tell application "Finder"
        repeat with objItem in (get selection)
            set end of filePath to POSIX path of (objItem as text)
        end repeat
    end tell

    set {strDelimeter, text item delimiters} to {text item delimiters, return}
    set the clipboard to filePath as text

    tell application "Safari" to open location filePath

end try
于 2013-11-18T05:58:39.217 に答える