2011-03-15 2 views
1

일반적으로 문제가되지 않는 전체 화면 앱을해야합니다. 이제는 10.7의 Launchpad와 마찬가지로 아이콘이없는 사용자의 데스크톱을 전체 화면 창 배경으로 사용해야한다는 문제가 있습니다. 나는 애플 스크립트에서 바탕 화면 배경에 대한 참조를 입수했습니다 document file "100930-F-7910D-001.jpg" of folder "Pictures" of folder "Fighter Jet Stuff" of folder "Desktop" of folder "tristan" of folder "Users" of startup disk of application "Finder" 난 그냥 정규 경로에 들어갈 알아낼 수 :코코아의 바탕 화면 배경을 얻으려면

tell application "Finder" 
    set a to desktop picture 
end tell 

이 나에게 이런 일을 제공합니다.

나는 set a to desktop picture as POSIX path을 시도했지만 그게 내게 던졌습니다. AppleScript를 사용하지 않고 위의 AppleScript를 사용하여 경로를 얻거나 더 나은 방법으로 코코아에서이 작업을 수행 할 수있는 방법에 대한 아이디어는 무엇입니까? 나중에 깨뜨릴 가능성이 있기 때문에이 정보를 저장할 수있는 plist의 특정 형식에 의존하지 않으려합니다. 내가 알지 못하는 프레임 워크가있을 수 있다고 생각합니다 ...

답변

7

찾고있는 방법은 NSWorkspace에서 사용할 수 있습니다. 당신은 단지 현재의 바탕 화면을 필요로하는 경우 NSWorkspace Class Reference

+0

감사합니다, 나는 완전히 그것을 간과. 나는 내 삶을 과도하게 복잡하게 만드는 대신에 먼저 거기를보아야했다. 나는 봤지 ... 아무것도. 감사! = P –

+1

바탕 화면 이미지가 매 x 초마다 "그림 변경"으로 설정된 경우이 방법은 작동하지 않으며 포스터의 바탕 화면도 마찬가지입니다. 이 경우 적절한 경로를 얻는 방법을 알아낼 수 없었습니다. – regulus6633

+0

당신은 그것에 대한 답변을 찾았습니까? –

0

, 당신은 그것의 스크린 샷을 수행 할 수 있습니다 :

– desktopImageURLForScreen: 
– setDesktopImageURL:forScreen:options:error: 
– desktopImageOptionsForScreen: 

여기 문서에서 봐 주시기 바랍니다

extension NSImage { 

    static func desktopPicture() -> NSImage { 

     let windows = CGWindowListCopyWindowInfo(
      CGWindowListOption.OptionOnScreenOnly, 
      CGWindowID(0))! as NSArray 

     var index = 0 
     for var i = 0; i < windows.count; i++ { 
      let window = windows[i] 

      // we need windows owned by Dock 
      let owner = window["kCGWindowOwnerName"] as! String 
      if owner != "Dock" { 
       continue 
      } 

      // we need windows named like "Desktop Picture %" 
      let name = window["kCGWindowName"] as! String 
      if !name.hasPrefix("Desktop Picture") { 
       continue 
      } 

      // wee need the one which belongs to the current screen 
      let bounds = window["kCGWindowBounds"] as! NSDictionary 
      let x = bounds["X"] as! CGFloat 
      if x == NSScreen.mainScreen()!.frame.origin.x { 
       index = window["kCGWindowNumber"] as! Int 
       break 
      } 
     } 

     let cgImage = CGWindowListCreateImage(
      CGRectZero, 
      CGWindowListOption(arrayLiteral: CGWindowListOption.OptionIncludingWindow), 
      CGWindowID(index), 
      CGWindowImageOption.Default)! 

     let image = NSImage(CGImage: cgImage, size: NSScreen.mainScreen()!.frame.size) 
     return image 
    } 
} 
관련 문제