2016-12-03 6 views
0

オートメーション用のJavaScriptで遊んでいると、AppleScriptでは非常に単純なことはできません。 (ショッカーは、私が知っている。)オートメーション用のJavaScriptを使用してFinderですべてを選択解除

これはAppleScript:

tell application "Finder" to set selection to {} 

は、Finderで選択をクリアします。

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 

任意の提案ですか?

(MacOSのシエラ、スクリプトエディタ2.9)

答えて

0

[編集]は、ここではより良い検討するかもしれないもう一つの "回避策" です。 ------------

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

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

: これはJXA(トリックは右のエスケープ文字を取得することはもちろんである)を介してシェルを行うことにより、呼び出されるosascriptを通じたスクリプトのAppleScriptのバージョンを送信します元の答え-------------

[OK]私はこの回答をお詫び申し上げますが、奇妙な回避策を介して、うまくいくと思うカップルの時間のためにそれを再生した後、より洗練されたソリューションを取得しないでください。誰が知っている、多分あなたはこのエレガントな見つけるでしょう。私はほとんどする。または、誰かがより良いものでチャイムを鳴らすでしょう。また、私はスクリプトエディタでこれを混乱させてきました。ああ、また、私はまだ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

ええ、あなたの2番目の解決策は、私が行ったことです。そのようなハイブリッドは、最もエレガントではないかもしれませんが、ウィンドウを閉じて再オープンするよりも優れています。ありがとう! –

関連する問題