QuickLook

[QuickLook]設定:FinderがフォアグラウンドでないときにQuick Look ウィンドウを隠す


AppleScript サンプルコード

【スクリプトエディタで開く】 |

AppleScript サンプルソース(参考)
行番号ソース
001#!/usr/bin/env osascript
002----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
003#com.cocolog-nifty.quicktimer.icefloe
004# 設定変更をユーザーが選択するパターンのサンプル
005----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
006
007
008##################
009#現在の設定値の確認
010set strCommandText to ("/usr/bin/defaults  read  com.apple.Finder QLHidePanelOnDeactivate") as text
011log ("\r" & strCommandText & "\r") as text
012set strExecCommand to ("/bin/zsh -c \"" & strCommandText & "\"") as text
013try
014  set strResponse to (do shell script strExecCommand) as text
015  set boolNotExist to false as boolean
016on error
017  log "zshでエラーになりました\r" & strCommandText & "\r"
018  set boolNotExist to true as boolean
019end try
020
021##################
022#戻り値による分岐
023if boolNotExist is true then
024  set strMes to ("現在設定されていません\nFinderがフォアグラウンドでないときにQuick Look ウィンドウを隠す\nTRUE:0 FALSE:0でTRUEを設定します") as text
025  set strCommandText to ("/usr/bin/defaults  write  com.apple.Finder QLHidePanelOnDeactivate  -bool true") as text
026else if strResponse is "1" then
027  set strMes to ("現在の設定はTRUE:1ですFALSE:0にしますか?") as text
028  set strCommandText to ("/usr/bin/defaults  write  com.apple.Finder QLHidePanelOnDeactivate  -bool false") as text
029else if strResponse is "0" then
030  set strMes to ("現在の設定はFALSE:0ですTRUE:1にしますか?") as text
031  set strCommandText to ("/usr/bin/defaults  write  com.apple.Finder QLHidePanelOnDeactivate  -bool true") as text
032end if
033
034##################
035#アラート選択
036try
037  #前面に
038  set strName to (name of current application) as text
039  if strName is "osascript" then
040    tell application "Finder" to activate
041  else
042    tell current application to activate
043  end if
044  set recordResponse to (display alert strMes buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" as informational giving up after 10) as record
045on error
046  log "キャンセルしました。"
047  return "キャンセルしました。"
048end try
049if true is equal to (gave up of recordResponse) then
050  return "時間切れです。"
051end if
052#アラートの戻り値
053set strBottonName to (button returned of recordResponse) as text
054
055
056##################
057#戻り値でコマンドを実行する
058if "OK" is equal to (strBottonName) then
059  log ("\r" & strCommandText & "\r") as text
060  set strExecCommand to ("/bin/zsh -c \"" & strCommandText & "\"") as text
061  try
062    set strResponse to (do shell script strExecCommand) as text
063  on error
064    log "zshでエラーになりました\r" & strCommandText & "\r"
065  end try
066end if
067
068
069
070return
AppleScriptで生成しました

|

[Applescript]OpenSaveパネルを終了させる(ちょっと修正)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
##UIDを取得する
set objSysInfo to system info
set strUserID to (user ID of objSysInfo) as text
################################################
##QuickLookのユーザープロセスPIDを取得
set strCommandText to ("/bin/ps -alx | grep " & strUserID & " | grep 'QuickLook' | grep -v grep | awk '{print $2}'") as text
set strResponse to (do shell script strCommandText) as text
##リストにして
set AppleScript's text item delimiters to "\r"
set listPID to every text item of strResponse
set AppleScript's text item delimiters to ""
set numCntPID to (count of listPID) as integer
if numCntPID = 0 then
log "プロセス無し終了"
end if
##プロセスがあれば終了していく
repeat with itemPID in listPID
  set strPID to itemPID as text
  set strCommandText to ("/bin/kill -9 " & strPID & "")
do shell script strCommandText
end repeat

################################################
##openAndSavePanelServiceのユーザープロセスPIDを取得
set strCommandText to ("/bin/ps -alx | grep " & strUserID & " | grep 'openAndSavePanelService' | grep -v grep | awk '{print $2}'") as text
set strResponse to (do shell script strCommandText) as text
##リストにして
set AppleScript's text item delimiters to "\r"
set listPID to every text item of strResponse
set AppleScript's text item delimiters to ""
set numCntPID to (count of listPID) as integer
if numCntPID = 0 then
return "プロセス無し終了"
end if
##プロセスがあれば終了していく
repeat with itemPID in listPID
  set strPID to itemPID as text
  set strCommandText to ("/bin/kill -9 " & strPID & "")
do shell script strCommandText
end repeat

return



#com.apple.quicklook.QuickLookUIService
#QuickLookUIService

|

[bash]OpenSaveパネルを終了させる(ちょっと修正)


#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
###UID
STR_UID=$(/usr/bin/id -u)
/bin/echo "ユーザー名(id): $STR_UID"
###PID
STR_PID=$(/bin/ps -alx | grep "$STR_UID" | grep 'QuickLook' | grep -v grep | awk '{print $2}')
/bin/echo "プロセスID: $STR_PID"
###リストにする
read -d '\\n' -r -a LIST_PID <<<"$STR_PID"
###リスト内の項目数
NUM_CNT=${#LIST_PID[@]}
/bin/echo "プロセス数:" "$NUM_CNT"
##リストの数だけ終了させる
for ITEM_LIST in "${LIST_PID[@]}"; do
/bin/kill -9 "$ITEM_LIST"
done
sleep 1
###PID
STR_PID=$(/bin/ps -alx | grep "$STR_UID" | grep 'openAndSavePanelService' | grep -v grep | awk '{print $2}')
/bin/echo "プロセスID: $STR_PID"
###リストにする
read -d '\\n' -r -a LIST_PID <<<"$STR_PID"
###リスト内の項目数
NUM_CNT=${#LIST_PID[@]}
/bin/echo "プロセス数:" "$NUM_CNT"
##リストの数だけ終了させる
for ITEM_LIST in "${LIST_PID[@]}"; do
/bin/kill -9 "$ITEM_LIST"
done

exit 0


|

[bash]OpenSaveパネルを終了させる

ディスク "XXXXXXX" を取り出せませんでした。1つ以上のプログラムが使用している可能性があります。
すぐにディスクを取り出すには、"強制的に取り出ず"ボタンをクリックします。が出た時用 Screen_2_20240201172201

#!/bin/bash
#com.cocolog-nifty.quicktimer.icefloe
#################################################
###UID
STR_UID=$(/usr/bin/id -u)
/bin/echo "ユーザー名(id): $STR_UID"
###PID
STR_PID=$(/bin/ps -alx | grep "$STR_UID" | grep 'QuickLookUIService' | grep -v grep | awk '{print $2}')
/bin/echo "プロセスID: $STR_PID"
###リストにする
read -d '\\n' -r -a LIST_PID <<<"$STR_PID"
###リスト内の項目数
NUM_CNT=${#LIST_PID[@]}
/bin/echo "プロセス数:" "$NUM_CNT"
##リストの数だけ終了させる
for ITEM_LIST in "${LIST_PID[@]}"; do
/bin/kill -9 "$ITEM_LIST"
done

exit 0


|

OpenSaveパネルを終了させる

ディスク "XXXXXXX" を取り出せませんでした。1つ以上のプログラムが使用している可能性があります。
すぐにディスクを取り出すには、"強制的に取り出ず"ボタンをクリックします。が出た時用 Screen_2_20240201172201

【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions
property refMe : a reference to current application
##UIDを取得する
set objSysInfo to system info
set strUserID to (user ID of objSysInfo) as text
##OPENパネルのPIDを取得
set strCommandText to ("/bin/ps -alx | grep " & strUserID & " | grep 'QuickLookUIService' | grep -v grep | awk '{print $2}'") as text
set strResponse to (do shell script strCommandText) as text
##リストにして
set AppleScript's text item delimiters to "\r"
set listPID to every text item of strResponse
set AppleScript's text item delimiters to ""
set numCntPID to (count of listPID) as integer
if numCntPID = 0 then
return "プロセス無し終了"
end if
##プロセスがあれば終了していく
repeat with itemPID in listPID
  set strPID to itemPID as text
  set strCommandText to ("/bin/kill -9 " & strPID & "")
do shell script strCommandText
end repeat

return



#com.apple.quicklook.QuickLookUIService
#QuickLookUIService

|

Finder再起動(QuickLookも)


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use framework "UniformTypeIdentifiers"
use scripting additions

property refMe : a reference to current application

set strBundleID to "com.apple.finder"


##バンドルからアプリケーションのURLを取得
set ocidAppBundle to (refMe's NSBundle's bundleWithIdentifier:(strBundleID))
if ocidAppBundle ≠ (missing value) then
  set ocidAppPathURL to ocidAppBundle's bundleURL()
else if ocidAppBundle = (missing value) then
  set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
  set ocidAppPathURL to (appSharedWorkspace's URLForApplicationWithBundleIdentifier:(strBundleID))
end if
##予備(アプリケーションのURL)
if ocidAppPathURL = (missing value) then
  tell application "Finder"
    try
      set aliasAppApth to (application file id strBundleID) as alias
      set strAppPath to POSIX path of aliasAppApth as text
      set strAppPathStr to refMe's NSString's stringWithString:(strAppPath)
      set strAppPath to strAppPathStr's stringByStandardizingPath()
      set ocidAppPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(strAppPath) isDirectory:true
    on error
return "アプリケーションが見つかりませんでした"
    end try
  end tell
end if

##終了
set ocidRunningApplication to refMe's NSRunningApplication
###起動中のすべてのリスト
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat
###起動
set ocidOpenConfig to refMe's NSWorkspaceOpenConfiguration's configuration
###コンフィグ
(ocidOpenConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
###起動
set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
(appSharedWorkspace's openApplicationAtURL:(ocidAppPathURL) configuration:(ocidOpenConfig) completionHandler:(missing value))


###ついでにQuickLOOK関連も再起動しておく

set strBundleID to "br.com.guilhermerambo.AssetCatalog"
##終了
set ocidRunningApplication to refMe's NSRunningApplication
###起動中のすべてのリスト
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat

set strBundleID to "com.latenightsw.sdquicklookgenerator"
##終了
set ocidRunningApplication to refMe's NSRunningApplication
###起動中のすべてのリスト
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat

set strBundleID to "com.apple.quicklook.QuickLookUIService"
##終了
set ocidRunningApplication to refMe's NSRunningApplication
###起動中のすべてのリスト
set ocidAppArray to (ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID))
###複数起動時も順番に終了
repeat with itemAppArray in ocidAppArray
  ###終了
itemAppArray's terminate()
end repeat
##1秒まって終了を確認
delay 1
##終了できない場合は強制終了
repeat with itemAppArray in ocidAppArray
  set boolTerminate to itemAppArray's terminated
  if boolTerminate = false then
itemAppArray's forceTerminate()
  end if
end repeat

|

[qlmanage]SVG to PNG


【スクリプトエディタで開く】|

#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#qlmanage クイックルックを使ってSVGをPNGに
#
#com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
##自分環境がos12なので2.8にしているだけです
use AppleScript version "2.8"
use framework "Foundation"
use scripting additions


property refMe : a reference to current application

###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if

####ダイアログ用デスクトップパス
set aliasDefaultLocation to path to desktop folder from user domain as alias
####ダイアログ
set listChooseFiles to (choose file with prompt "ファイルを選んでください" default location aliasDefaultLocation of type {"public.svg-image"} with multiple selections allowed without showing package contents and invisibles) as list

#############################
###ダイアログ
set strName to (name of current application) as text
if strName is "osascript" then
  tell application "Finder" to activate
else
  tell current application to activate
end if
############
set aliasDefaultLocation to (path to desktop folder from user domain) as alias
############
set strMes to "フォルダを選んでください" as text
set strPrompt to "フォルダを選択してください" as text
try
  set aliasSaveDirPath to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation with invisibles and showing package contents without multiple selections allowed) as alias
on error
  log "エラーしました"
return "エラーしました"
end try

set strSaveDirPath to (POSIX path of aliasSaveDirPath) as text

####ファイルの数だけ繰り返し
repeat with objFile in listChooseFiles
  ###UNIXパスに変換
  set theFilePath to POSIX path of objFile as text
  ###スクリプトに渡す
  set strCommandText to ("\"/System/Library/Frameworks/QuickLook.framework/Versions/A/Resources/qlmanage.app/Contents/MacOS/qlmanage\" -t -s 800 \"" & theFilePath & "\" -o \"" & strSaveDirPath & "\"") as text
  do shell script strCommandText
  
end repeat



  Usage: qlmanage [OPTIONS] path...
-h Display this help
-r Force reloading Generators list
-r cache Reset thumbnail disk cache
-m [name ...]   Display statistics about quicklookd. Stats names:
* plugins       Show the generators list
* server Show quicklookd life information
* memory Show quicklookd memory consumption
* burst Show statistics about the last burst
* threads       Show concurrent accesses stats
* other Show other information about quicklookd
-p Compute previews of the documents
-t Compute thumbnails of the documents
-x Use quicklookd (remote computation)
-i Compute thumbnail in icon mode
-s size Size for the thumbnail
-f factor       Scale factor for the thumbnail
-F factor       Scale factor for the thumbnail, draw downscaled and compare to 1x
-z Display generation performance info (don't display thumbnails)
-o dir Output result in dir (don't display thumbnails or previews)
-c contentType  Force the content type used for the documents
-g generator    Force the generator to use

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom