본문 바로가기
#컴퓨터 과학 [Computer Science]/운영체제 (Operating System)

[OS - 🍎 macOS] macOS 최근 사용 항목 목록 가져오기 (How to get list of recent items in macOS)

by cy_mos 2019. 12. 20.
반응형

최근 사용 항목 (Recent items)

 

최근 사용 항목 기능은 최근에 사용한 앱이 Apple 메뉴에서 목록으로 표시되고 Dock에 나타나도록합니다. 또한 최근에 사용한 앱 및 서버가 Apple 메뉴에서 목록으로 표시됩니다. 빠르게 앱 또는 파일을 다시 열거나 메뉴에서 서버에 다시 연결할 수 있습니다.

 

🔎 macOS 최근 사용 항목 수 변경하는 방법 (Change the number of items listed in the Apple menu)

Change the number of items listed in the Apple menu

 

[국문]

  • Mac에서 Apple 메뉴> 시스템 환경설정을 선택하고 일반을 클릭하여 최근 사용 항목 팝업 메뉴를 클릭한 다음 숫자를 선택합니다.

[영문]

  • On your Mac, choose Apple menu System Preferences, then click General. Click the Recent items pop-up menu, then choose a number.

📂 macOS 최근 사용 항목 경로 (Recent Items path)

~/Library/Application Support/com.apple.sharedfilelist

 

  • /Users/Library/Preferences/.LSShardFileList.plist   
  • /Users/Library/Preferences/com.apple.finder.plist   
  • [10.10-] /Users/Library/Preferences/com.apple.recentitems.plist   
  • [10.11+] /Users/Library/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/.sfl2
  • [10.11+] /Users/Library/Library/Application Support/com.apple.sharedfilelist/RecentApplications.sfl2
  • [10.11+] /Users/Library/Library/Application Support/com.apple.sharedfilelist/RecentDocuments.sfl2
  • [10.11+] /Users/Library/Library/Application Support/com.apple.sharedfilelist/RecentServers.sfl2
  • [10.11+] /Users/Library/Library/Application Support/com.apple.sharedfilelist/RecentHosts.sfl2

📔 Get List of recent items Source Code by AppleScript

pplAuse AppleScript version "2.5"
use framework "Foundation"
use scripting additions

property |⌘| : a reference to current application

set recentDocumentsPath to POSIX path of (path to application support from user domain) & "com.apple.sharedfilelist/com.apple.LSSharedFileList.RecentDocuments.sfl2"
set plistData to |⌘|'s NSData's dataWithContentsOfFile:recentDocumentsPath
set recentDocuments to |⌘|'s NSKeyedUnarchiver's unarchiveObjectWithData:plistData
set documentPaths to {}
repeat with aDocument in (recentDocuments's objectForKey:"items")
   set documentBookmark to (aDocument's objectForKey:"Bookmark")
   set {documentURL, resolveError} to (|⌘|'s NSURL's URLByResolvingBookmarkData:documentBookmark options:0 relativeToURL:(missing value) bookmarkDataIsStale:(missing value) |error|:(reference))
   if resolveError is missing value then
       set end of documentPaths to documentURL's |path|()
   else
       display dialog resolveError's localizedDescription as text
   end if
end repeat

📔 Get List of recent items Source Code by Swift

Get-Recent-Item.swift
0.00MB

 
// com.apple.LSSharedFileList.RecentDocuments.sfl2
if let data = FileManager.default.contents(atPath: "/Users/[USER_NAME]/Documents/com.apple.LSSharedFileList.RecentDocuments.sfl2") {
    if let result = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(data) as? NSDictionary {
        if let processing = result["items"] as? NSArray {
            //print(result.allKeys)
            //print(result.allValues)
            
            for item in processing {
                if let dict = item as? NSDictionary, let res = dict["Bookmark"] as? Data {
                    let path = try NSURL(resolvingBookmarkData: res, options: [], relativeTo: nil, bookmarkDataIsStale: nil)
                    print(path.path)
                }
            }
        }
    }
}

// com.apple.LSSharedFileList.RecentApplications.sfl2
if let dataTwo = FileManager.default.contents(atPath: "/Users/[USER_NAME]/Documents/com.apple.LSSharedFileList.RecentApplications.sfl2") {
    if let result = try NSKeyedUnarchiver.unarchiveTopLevelObjectWithData(dataTwo) as? NSDictionary {
        if let processing = result["items"] as? NSArray {
            
            for item in processing {
                if let dict = item as? NSDictionary, let res = dict["Bookmark"] as? Data {
                    let path = try NSURL(resolvingBookmarkData: res, options: [], relativeTo: nil, bookmarkDataIsStale: nil)
                    print(path.path)
                }
            }
        }
    }
}

🚀 REFERENCE

 

MacScripter / How to get list of recent items

 

macscripter.net

 

Find the Last Accessed Date of a File in Cocoa

Is it possible to get file/folder last accessed date in mac using cocoa? struct stat output; //int ret = stat([[[openPanel filenames] lastObject] UTF8String], &output); int ret = s...

stackoverflow.com

 

Apple's BookmarkData - exposed!

the vent for my mind

michaellynn.github.io

 

New Script! - MacMRU (Most Recently Used) Plist Parser — mac4n6.com

96 Normal 0 false false false EN-US X-NONE X-NONE

www.mac4n6.com

 

반응형

댓글