2013-08-09 2 views
0

Chrome에서 활성 문서를 열 수있는 textwrangler 용 AppleScript를 작성하려고합니다. 이 스크립트가 순간에 모습입니다 : http : // localhost with applescript를 사용하여 브라우저에서 php 파일 열기

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

이의는 내가 절대 경로 '응용 프로그램/MAMP/www /에서의 index.php'로 파일 작업을한다고 가정 해 봅시다. 스크립트는 브라우저에서 'file : // localhost/Applications/MAMP/www/index.php'파일을 열어 php 코드를 보여줍니다.

대신 'file : // localhost/Applications/MAMP /'를 'http : // localhost /'로 바꾸어 실제 사이트를 나타내는 스크립트가 필요합니다.

나는 온라인에서 찾은 많은 것들을 시도했지만, 이것을 달성하기에는 AppleScript로는 경험이 거의 없다. 도움이

tell application "Safari" 
    activate 
    do JavaScript "window.open('http:// localhost/')" in document 1 
end tell 

희망 : 당신은 그냥 URL을 열려면

+0

나는 순서로 localhost를하기 전에 공백이 이 질문을 제출하십시오. – MacBryce

답변

0

어때 이것에 대해, 체이스의 리드와 자바 스크립트를 사용하여 교체 문자열을 할.

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());") 

다중 언어 연결 및 문자열 구분으로 코드를 읽기가 어려워 지지만 작동해야합니다.

+0

감사합니다. 그것이 내가 찾고 있던 것입니다. – MacBryce

0

, 당신은 같은 것을 사용합니다.

+0

고마워,하지만 내가 무엇을 찾고 원래 경로 (문자열?) 기본적으로 트림하고 'http : // localhost /'비트를 시작 부분에 추가 할 수 있습니다. – MacBryce

+0

문자열에 변수를 추가하고 &&를 사용하여 tell에 넣을 수 있습니까? – Chase

0

여기에 첫 번째는 열려는 파일이 루트 로컬 호스트 디렉토리에 있다고 가정 몇 가지 다른 옵션 ..

을합니다. 스크립트는 Safari가 URL을 열고 경로에 파일 이름을 추가하도록 지시합니다.

처음 실행하면 을 실행할 때 Mac 접근성을 인증해야 Finder에서 필요한 작업을 완료 할 수 있습니다.


또 다른 옵션은 선택한 파일의 POSIX 경로를 복사 Safari에서 로컬 경로를 열 것

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 
..

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