Edama2さんから投稿していただいた、デスクトップを隠すAppleScriptアプレットです。
資料や本のために画面キャプチャを行うさい、デスクトップを隠しておく(アイコンとかデスクトップピクチャとか)必要があるケースがあります。そのような用途のために作られたものです。
AppleScript名:デスクトップを隠すv6 |
script HideDesktop use AppleScript version "2.4" use scripting additions use framework "Foundation" use framework "Carbon" — AEInteractWithUser() is in Carbon #GUI部品のtag property _TAG_OF_COLOR_WELL : 501 property _TAG_OF_SLIDER : 502 property _TAG_OF_BUTTON : 503 on run if current application’s AEInteractWithUser(-1, missing value, missing value) is not equal to 0 then return #色データを復元 if my _color_data = missing value then set myColor to current application’s NSColor’s colorWithCalibratedRed:0.2 green:0.3 blue:0.5 alpha:1 else set str to current application’s NSString’s stringWithString:(my _color_data) set enc to current application’s NSISOLatin1StringEncoding set strData to str’s dataUsingEncoding:(enc) set myColor to current application’s NSUnarchiver’s unarchiveObjectWithData:strData end if activate my makeSettingWindow(myColor, my _alpha_value, my _is_show_icon) end run on quit repeat with aWin in (current application’s NSApp’s |windows|()) set aSound to missing value if aWin’s styleMask() = current application’s NSBorderlessWindowMask then try tell current application’s NSSound’s alloc() tell initWithContentsOfFile_byReference_("/Applications/Messages.app/Contents/Resources/Default.aiff", true) set dTime to currentTime() play() set aSound to it end tell end tell end try end if (my closeWin:(aWin)) if aSound ≠ missing value then delay (dTime + 0.5) end repeat –continue quit end quit on makeSettingWindow(myColor, alphaVal, isShowIcon) #NSView tell current application’s NSView’s alloc() tell initWithFrame_(current application’s NSMakeRect(0, 0, 360, 210)) setNeedsDisplay_(true) set aView to it end tell end tell #Labelをつくる tell current application’s NSTextField’s alloc() tell initWithFrame_(current application’s NSMakeRect(60, 150, 80, 20)) setEditable_(false) setStringValue_("背景色:") setDrawsBackground_(false) setBordered_(false) setAlignment_(current application’s NSRightTextAlignment) aView’s addSubview:it end tell end tell tell current application’s NSTextField’s alloc() tell initWithFrame_(current application’s NSMakeRect(60, 110, 80, 20)) setEditable_(false) setStringValue_("透明度:") setDrawsBackground_(false) setBordered_(false) setAlignment_(current application’s NSRightTextAlignment) aView’s addSubview:it end tell end tell tell current application’s NSTextField’s alloc() tell initWithFrame_(current application’s NSMakeRect(60, 70, 80, 20)) setEditable_(false) setStringValue_("オプション:") setDrawsBackground_(false) setBordered_(false) setAlignment_(current application’s NSRightTextAlignment) aView’s addSubview:it end tell end tell #Color Well tell current application’s NSColorWell’s alloc() tell initWithFrame_(current application’s NSMakeRect(140, 150, 180, 20)) setColor_(myColor) setTag_(my _TAG_OF_COLOR_WELL) aView’s addSubview:it end tell end tell #スライダー tell current application’s NSSlider’s alloc() tell initWithFrame_(current application’s NSMakeRect(140, 110, 180, 20)) setMaxValue_(100) setMinValue_(10) –setNumberOfTickMarks_(25) setKnobThickness_(1) setAllowsTickMarkValuesOnly_(true) setTickMarkPosition_(current application’s NSTickMarkBelow) setIntValue_(alphaVal) setTag_(my _TAG_OF_SLIDER) aView’s addSubview:it end tell end tell #アイコンを隠すか tell current application’s NSButton’s alloc() tell initWithFrame_(current application’s NSMakeRect(140, 70, 180, 20)) — pullsDown:false setButtonType_(current application’s NSSwitchButton) setTitle_("アイコンも隠す") setState_(isShowIcon) setTag_(my _TAG_OF_BUTTON) aView’s addSubview:it end tell end tell #OK/Cancel Button tell current application’s NSButton’s alloc() tell initWithFrame_(current application’s NSMakeRect(110, 10, 90, 40)) setButtonType_(current application’s NSMomentaryLightButton) setBezelStyle_(current application’s NSRoundedBezelStyle) setTitle_("Cancel") setTarget_(me) setAction_("clicked:") setKeyEquivalent_(ASCII character (27)) aView’s addSubview:it end tell end tell tell current application’s NSButton’s alloc() tell initWithFrame_(current application’s NSMakeRect(210, 10, 90, 40)) setButtonType_(current application’s NSMomentaryLightButton) setBezelStyle_(current application’s NSRoundedBezelStyle) setTitle_("OK") setTarget_(me) setAction_("clicked:") setKeyEquivalent_(return) aView’s addSubview:it end tell end tell set aTitle to current application’s name as text #Window set aScreen to current application’s NSScreen’s mainScreen() set aFrame to aView’s frame() set aBacking to current application’s NSTitledWindowMask set aDefer to current application’s NSBackingStoreBuffered tell current application’s NSWindow’s alloc() tell initWithContentRect_styleMask_backing_defer_screen_(aFrame, aBacking, aDefer, false, aScreen) –setLevel_(current application’s NSNormalWindowLevel) setTitle_(aTitle) setDelegate_(me) setDisplaysWhenScreenProfileChanges_(true) setHasShadow_(true) setIgnoresMouseEvents_(false) setOpaque_(false) setReleasedWhenClosed_(true) setContentView_(aView) |center|() makeKeyAndOrderFront_((me)) end tell end tell end makeSettingWindow #ボタンをクリックした時 on clicked:aSender #カラーパネルを閉じる tell current application’s NSColorPanel if (sharedColorPanelExists() as boolean) then sharedColorPanel()’s |close|() end tell #設定値の読み込み tell aSender’s superview() set myColor to viewWithTag_(my _TAG_OF_COLOR_WELL)’s |color|() set alphaVal to viewWithTag_(my _TAG_OF_SLIDER)’s intValue() set isShowIcon to viewWithTag_(my _TAG_OF_BUTTON)’s state() end tell #Windowを閉じる my closeWin:(aSender’s |window|()) set aTitle to aSender’s title() as text if aTitle = "OK" then #デスクトップを隠す set {myColor, my _alpha_value, my _is_show_icon} to my makeCoverWindow(myColor, alphaVal, isShowIcon) #NSColor–>NSData–>NSString set aData to current application’s NSArchiver’s archivedDataWithRootObject:(myColor) set enc to current application’s NSISOLatin1StringEncoding set str to current application’s NSString’s alloc()’s initWithData:(aData) encoding:enc set my _color_data to str as text else if aTitle = "Cancel" then tell current application to quit end if end clicked: #ウィンドウを作成 on makeCoverWindow(myColor, alphaVal as integer, isShowIcon as boolean) set aScreen to current application’s NSScreen’s mainScreen() set screenFrame to aScreen’s frame() set aBacking to current application’s NSBorderlessWindowMask set aDefer to current application’s NSBackingStoreBuffered set aHeight to screenFrame’s |size|’s height set aWidth to screenFrame’s |size|’s width set aFrame to current application’s NSMakeRect(0.0, aHeight, aWidth, aHeight) #Image tell current application’s NSImage’s alloc() tell initWithSize_(screenFrame’s |size|) lockFocus() set theColor to myColor’s colorWithAlphaComponent:(alphaVal / 100) tell current application’s NSBezierPath’s bezierPath() appendBezierPathWithRect_(screenFrame) theColor’s |set|() fill() end tell unlockFocus() set anImage to it end tell end tell #View tell current application’s NSImageView’s alloc() tell initWithFrame_(aFrame) setNeedsDisplay_(true) setImage_(anImage) set aCustView to it end tell end tell #Window tell current application’s NSWindow’s alloc() tell initWithContentRect_styleMask_backing_defer_screen_(aFrame, aBacking, aDefer, false, aScreen) #アイコンの表示 if not isShowIcon then setLevel_(current application’s kCGDesktopWindowLevel) else setLevel_(((current application’s kCGBackstopMenuLevelKey) – 100)) –>メニューバーの影のため100ひく end if setBackgroundColor_(current application’s NSColor’s clearColor()) setContentView_(aCustView) setDelegate_(me) setDisplaysWhenScreenProfileChanges_(true) setHasShadow_(false) setIgnoresMouseEvents_(false) setOpaque_(false) setReleasedWhenClosed_(true) makeKeyAndOrderFront_((me)) #Sound try (current application’s NSSound’s alloc()’s initWithContentsOfFile:"/Applications/Messages.app/Contents/Resources/Invitation Accepted.aiff" byReference:true)’s play() on error the error_message number the error_number (current application’s NSSound’s soundNamed:"Purr")’s play() end try setFrame_display_animate_(screenFrame, true, true) end tell end tell return {myColor, alphaVal, isShowIcon} end makeCoverWindow #close win on closeWin:aWindow repeat with n from 10 to 1 by -1 (aWindow’s setAlphaValue:n / 10) delay 0.02 end repeat aWindow’s |close|() delay 0.02 end closeWin: end script #設定値 property _color_data : missing value property _alpha_value : 100 property _is_show_icon : true on run run of HideDesktop end run on quit quit of HideDesktop continue quit end quit |