desktopImageURLForScreen
デスクトップ画像のある場所を返します
- (NSURL *)desktopImageURLForScreen:(NSScreen *)screen
func desktopImageURLForScreen(_ screen: NSScreen) -> NSURL?
解説
デスクトップ画像のファイルのある場所を返します。
この場合のデスクトップ画像とは、スクリーンショットではなく、現在適用されている壁紙自体のことです。
タイル状になっている場合は、その1枚分の画像です。
返り値
NSURL *NSURL
引数
(NSScreen *)screen_ screen: NSScreen
フレームワーク
ApplicationKit
クラス
NSWorkspace
使用可能
10.6-
更新時のバージョン
OS X 10.10.3
Swift1.2
参照
関連記事(外部サイト)
例文
//NSWorkspace desktopImageURLForScreen @IBAction func function038(sender: AnyObject) { var aWindow : NSWindow = NSWindow(contentRect: NSMakeRect(0.0, 0.0, 300, 200), styleMask: NSTitledWindowMask | NSClosableWindowMask | NSMiniaturizableWindowMask | NSResizableWindowMask, backing: .Buffered, defer: false) windowArray.addObject(aWindow) //ウインドウを保持するための配列に追加。アプリ終了時に配列は破棄 //テーブルビューを作成 //まずはスクロールビュー var scrollView : NSScrollView = NSScrollView(frame: NSMakeRect(0.0,30.0,300.0,170.0)) //中身のイメージビュー var theImageView : NSImageView = NSImageView(frame: NSMakeRect(0.0,30.0,1000.0,1000.0)) //デスクトップ画像を取得 let theWorkspace : NSWorkspace = NSWorkspace.sharedWorkspace() var theURL : NSURL = theWorkspace.desktopImageURLForScreen(NSScreen.mainScreen()!)! let img : NSImage = NSImage(contentsOfURL: theURL)! theImageView.image = img scrollView.documentView = theImageView scrollView.hasVerticalRuler = true scrollView.hasHorizontalScroller = true scrollView.hasVerticalScroller = true scrollView.hasHorizontalRuler = true aWindow.contentView.addSubview(scrollView) scrollView.translatesAutoresizingMaskIntoConstraints = false //ウインドウに対するスクロールビューの制約 var scrollViewConstraints : NSMutableArray = NSMutableArray() var viewDictionary3 : Dictionary = ["scrollView": scrollView] var scrollViewConstraintV:[AnyObject] = NSLayoutConstraint.constraintsWithVisualFormat( "V:|-(5)-[scrollView]-(30)-|", options : NSLayoutFormatOptions(0), metrics: nil, views: viewDictionary3) scrollViewConstraints.addObjectsFromArray(scrollViewConstraintV) //横の制約 スクロールビューが親ビューに対して var scrollViewConstraintH:[AnyObject] = NSLayoutConstraint.constraintsWithVisualFormat( "H:|-(5)-[scrollView]-(5)-|", options : NSLayoutFormatOptions(0), metrics: nil, views: viewDictionary3) scrollViewConstraints.addObjectsFromArray(scrollViewConstraintH) //ウインドウに対するスクロールビューの制約の追加 aWindow.contentView.addConstraints(scrollViewConstraints as [AnyObject]) //ウインドウの表示 aWindow.center()//ウインドウをスクリーンの中心に aWindow.title = "ウインドウタイトル"//タイトル設定 aWindow.orderFront(self)//前面に aWindow.makeKeyAndOrderFront(self)//表示 }