2016-12-03 4 views
0

자동화 용 JavaScript로 놀아 보면서 AppleScript에서 매우 단순한 작업을 수행 할 수 없습니다. (쇼커, 나는 알고있다.)자동화 용 JavaScript를 사용하여 Finder에서 모두 선택 해제

이 애플 스크립트 :

tell application "Finder" to set selection to {} 

파인더의 선택을 지 웁니다.

JXA에서 동일한 작업을 수행하는 방법을 알 수 없습니다. 여기

내가 무엇을 시도했다입니다 :

var finder = Application("Finder") 
finder.includeStandardAdditions = true 
    //this selects files in the front window... 
finder.select([...array of file paths...]) 
    //so you'd think this might work to deselect all... 
finder.select([]) 
    //...but it doesn't do anything 

//then I tried each of these in turn... 

finder.select(null) 
    //Error -10010: Handler can't handle objects of this class. 

finder.selection = null 
    //Error -10010: Handler can't handle objects of this class. 

finder.selection = [] 
    //Script Editor crashes 

//...but none were successful 

어떤 제안?

(맥 OS 시에라, 스크립트 편집기 2.9)

답변

0

[편집] 여기에 또 다른는 "주위에 작업"당신이 고려할 수있는 더 나은 . ------------

var app = Application.currentApplication(); 
app.includeStandardAdditions = true; 

app.doShellScript('osascript -e "tell application \\"Finder\\" to set selection to {}"'); 

: 이 JXA (트릭 바로 이스케이프 문자를 얻을 수 물론이다)를 통해 쉘을 호출 osascript을 통해 스크립트의 애플 스크립트 버전을 전송 원래 대답 -------------

Ok 나는이 대답에 대해 사과해야한다고 확신하지만, 이상하게도 해결할 수 있습니다. 몇 시간 동안 놀고 나면 더 우아한 해결책을 얻지 못한다. 누가 알겠습니까? 아마도이 우아함을 알게 될 것입니다. 나는 거의한다. 아니면 누군가가 더 나은 사람과 차임을 할 것입니다. 또한 필자는 Script Editor에서이 작업을 망쳤습니다. 아, 그리고 아직도, 나는 아직도 움직이고있다. 10.10.5

//this allows use of JXA version of do shell script later 
var app = Application.currentApplication(); 

app.includeStandardAdditions = true; 
var thefinder = Application("Finder"); 
//Would advise using if/then here to check if there's at least one window, like: 
// if (thefinder.windows.length != 0) { 

//gets front window (where selection is, always) 
var fWin = thefinder.windows[0]; 

//gets the "target", which is the folder ref 
var fWinTarget = fWin.target(); 

//gets the url of the target 
var winU = fWinTarget.url(); 

//makes that a path 
var winUPath = Path(winU); 

//closes the original finder window (ref) 
fWin.close(); 

//opens it up again! no more selection! 
app.doShellScript("open " + winU); 
+0

네, 두 번째 해결책은 내가 함께 일을 끝낸 것이다. 그런 하이브리드는 가장 우아하지는 않지만 창을 닫았다가 다시 열 때보다 낫습니다. 감사! –