デスクトップピクチャの表示状態と、単色黒色のデスクトップ+デスクトップ非表示状態のトグル切り替えを行うAppleScriptです。
資料や仕様書を作成する際に画面キャプチャを行うことが多いですが、その際にデスクトップに散らかっているファイルが映るとみっともないので、隠すために作成したものです。–> Demo Movie
1回実行するとデスクトップを隠し、もう1回実行すると元に戻ります。
AppleScript名:デスクトップピクチャを黒いピクチャとトグルで差し替え v2 |
— Created 2016-05-31 by Takaaki Naganoya — Modified 2016-06-01 by Takaaki Naganoya–Desktop Iconの表示/非表示を追加 — 2016 Piyomaru Software use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "AppKit" property aSwitch : false property desktopPictures : {} property aColpath : "" if aSwitch = false then –デスクトップを黒くする set desktopPictures to getDesktopPicturePathList() of me –白い画像を作成してデスクトップピクチャに設定 set aColor to current application’s NSColor’s blackColor() set aColpath to makeColordImageToTmp(aColor) of me setDesktopPicture(aColpath) of me showHideDesktop(false) of me set aSwitch to true else –保存しておいたDesktop Pictureのリストを戻す setDesktopPicturePathList(desktopPictures) of me do shell script "rm -f " & quoted form of aColpath showHideDesktop(true) of me set aSwitch to false end if –デスクトップの表示/非表示切り替え on showHideDesktop(aBool as boolean) set aBoolStr to aBool as string do shell script "defaults write com.apple.finder CreateDesktop -bool " & aBoolStr do shell script "killall Finder" end showHideDesktop –デスクトップピクチャの状態を復帰する on setDesktopPicturePathList(aliasList) if aliasList = {} then display notification "保存しておいたデスクトップピクチャのリストが空になっています" return end if tell application "System Events" set dCount to count every desktop repeat with i from 1 to dCount set j to contents of item i of aliasList tell desktop i set picture to (POSIX path of j) end tell end repeat end tell end setDesktopPicturePathList –デスクトップピクチャの強制指定 on setDesktopPicture(aPathStr) tell application "System Events" set picture of every desktop to aPathStr end tell end setDesktopPicture –デスクトップピクチャのパスをaliasリストで取得 on getDesktopPicturePathList() set pList to {} tell application "System Events" set dCount to count every desktop repeat with i from 1 to dCount tell desktop i set aPic to (picture as POSIX file) as alias set end of pList to aPic end tell end repeat end tell return pList end getDesktopPicturePathList –テンポラリフォルダに指定色の画像を作成 on makeColordImageToTmp(aColor) –set aColor to current application’s NSColor’s colorWithDeviceRed:rCol green:gCol blue:bCol alpha:aCol set aDesktopPath to current application’s NSString’s stringWithString:(POSIX path of (path to temporary items)) set savePath to aDesktopPath’s stringByAppendingString:((current application’s NSUUID’s UUID()’s UUIDString())’s stringByAppendingString:".png") set aRes to makeImageWithFilledWithColor(1, 1, savePath, aColor) of me return (savePath as string) end makeColordImageToTmp –指定サイズの画像を作成し、指定色で塗ってファイル書き出し on makeImageWithFilledWithColor(aWidth, aHeight, outPath, fillColor) –Imageの作成 set anImage to current application’s NSImage’s alloc()’s initWithSize:(current application’s NSMakeSize(aWidth, aHeight)) anImage’s lockFocus() –描画実行 set theRect to {{x:0, y:0}, {height:aHeight, width:aWidth}} set theNSBezierPath to current application’s NSBezierPath’s bezierPath theNSBezierPath’s appendBezierPathWithRect:theRect fillColor’s |set|() theNSBezierPath’s fill() anImage’s unlockFocus() –描画ここまで –生成した画像のRaw画像を作成 set imageRep to anImage’s TIFFRepresentation() set aRawimg to current application’s NSBitmapImageRep’s imageRepWithData:imageRep set myNewImageData to (aRawimg’s representationUsingType:(current application’s NSPNGFileType) |properties|:(missing value)) –書き出しファイルパス情報を作成 set pathString to current application’s NSString’s stringWithString:outPath set newPath to pathString’s stringByExpandingTildeInPath() set aRes to (myNewImageData’s writeToFile:newPath atomically:true) as boolean return aRes –成功ならtrue、失敗ならfalseが返る end makeImageWithFilledWithColor |
More from my site
(Visited 92 times, 1 visits today)