최근 Finder 폴더를 목록으로 반환하는 AppleScript Folders 메뉴를

나에게 반환 할 AppleScript를 써야한다. 명부 Finder에서 Recent Folders 메뉴를 엽니 다. 최근의 폴더를 목록으로 반환하는 스크립트가 필요합니다.

이것이 가능하다면 아마도 대화 상자와 함께 목록을 표시하여 시연하는 것이 좋습니다.

가능한가?

Menu



답변

MacScripter 스레드 폴더를 별칭으로 가져 오는 스크립트가 있지만 10.8에서 작동하지 않습니다. 더 이상 파일 데이터 키가 없지만 다음 중 하나는 작동하지 않습니다.

tell application "System Events"
    value of property list item "file-bookmark" of property list item 1 of property list item "FXRecentFolders" of contents of property list file "~/Library/Preferences/com.apple.finder.plist"
    try
        value of result
    on error err
        text 30 thru -4 of err
        (run script "«data alis" & result & "»") as alias
    end try
end tell

PlistBuddy를 사용하여 일반 텍스트 값을 인쇄 할 수 있습니다.

$ PlistBuddy -c 'Print FXRecentFolders:0:file-bookmark' ~/Library/Preferences/com.apple.finder.plist
book?0?Userslau?4A?x?iH???A?1M?$5DF7A03E-A7FB-3E80-B61D-F10CD8BF7B5D?/?6a0c3f51ea4eaf67e96c08fa9b69b93aee598f01;00000000;0000000000000020;com.apple.app-sandbox.read-write;00000001;01000002;000000000005ca9f;/users/lauri?????$Tt@d  ? ? ? ?  ?0 ???? ??,

의 핸들러 이 실 10.7에서는 작동했지만 10.8에서는 작동하지 않았습니다.

베이스 네임 만 있으면 별도의 키가 있습니다.

tell application "System Events" to value of property list item "name" of property list items of property list item "FXRecentFolders" of contents of property list file "~/Library/Preferences/com.apple.finder.plist"


답변

이 스크립트는 basename과 경로 위치를 반환합니다 :

on findPathSeparator(theData, theFile)
    set pathSeparator to {0, 0, 0, 1, 1, 0, 0}
    set bytesFound to 0
    set bytesSearched to 0

    try
        read theFile from 0 for 0

        set numIterations to 0

        repeat (get eof theFile) times
            set theId to id of (read theFile from bytesSearched for 1)

            if theId is item (bytesFound + 1) of pathSeparator then
                set bytesFound to bytesFound + 1
            else
                set bytesFound to 0
            end if

            if bytesFound is (count of pathSeparator) then exit repeat

            set bytesSearched to bytesSearched + 1
        end repeat
    on error msg
        msg
    end try

    return bytesSearched - (count of pathSeparator)
end findPathSeparator

on getPathFromData(theData)
    set pathSeparator to {0, 0, 0, 1, 1, 0, 0}

    set theFile to (open for access POSIX file ("/tmp/get_recent_folders") with write permission)

    set eof theFile to 0

    write contents of theData to theFile

    set startPosition to findPathSeparator(theData, theFile)

    try
        read theFile from startPosition for 0

        set thePath to ""

        repeat
            set idList to id of (read theFile for 8)

            if (idList does not end with pathSeparator) then exit repeat

            set theLength to item 1 of idList

            set thePath to thePath & ("/" & (read theFile for theLength as «class utf8»))

            read theFile for (4 - theLength mod 4) mod 4
        end repeat
    on error msg
        msg
    end try

    close access theFile

    return thePath
end getPathFromData

tell application "System Events"
    tell property list file "~/Library/Preferences/com.apple.finder.plist"
        set dataItems to property list item "FXRecentFolders"'s property list items's property list item "file-bookmark"'s value
        set itemNames to property list item "FXRecentFolders"'s property list items's property list item "name"'s value
    end tell
end tell

set theOutput to ""

set itemNum to 1
repeat (count of dataItems) times
    set theOutput to theOutput & item itemNum of itemNames & "
" & getPathFromData(item itemNum of dataItems) & "
"
    set itemNum to itemNum + 1
end repeat

theOutput