跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • 有办法能拿到 Mac 自带 preview 打开的 pdf 的进度吗?
未分類
29 11 月 2020

有办法能拿到 Mac 自带 preview 打开的 pdf 的进度吗?

有办法能拿到 Mac 自带 preview 打开的 pdf 的进度吗?

資深大佬 : Jooooooooo 2

搜了一下没搜着, 很可能是因为关键词不对

需求是多个 Mac 之间同步 pdf 的进度

找了很多方法都不行, 苹果自带 Books 不好用, Kindle 也不好用

我想着如果我能拿到本机是怎么保存 pdf 读取进度的, 我可以自己写个同步的小脚本自己用

大佬有話說 (2)

  • 資深大佬 : alaysh

    ~/Library//Containers/com.apple.Preview/Data/Library/Preferences/com.apple.Preview.ViewState.plist
    找到文件对应 Key 的 Data,用 plist 格式解开,elementIndex 就是所需的值。

    #import <Foundation/Foundation.h>
    #include <sys/stat.h>

    NSString *persistentIdForFileURL(NSURL *url) {
    NSString *persistentId;

    id value;
    NSError *error;
    BOOL res = [url getResourceValue:&value forKey:NSURLVolumeUUIDStringKey error:&error];
    if (res) {
    struct stat statBuf;
    int res = stat(url.fileSystemRepresentation, &statBuf);
    if (res == 0) {
    persistentId = [NSString stringWithFormat:@”%@.%llu”, value, statBuf.st_ino];
    }
    else {
    NSLog(@”stat error: %d”, res);
    }
    }
    else {
    NSLog(@”getResourceValue error:%@”, error);
    }
    return persistentId;
    }

    int main(int argc, const char * argv[]) {
    @autoreleasepool {
    NSURL *url = [NSURL URLWithString:@”file:///tmp/1.pdf”];
    NSString *persistentId = persistentIdForFileURL(url);

    NSString *path = NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, true)[0];
    path = [path stringByAppendingString:@”/Containers/com.apple.Preview/Data/Library/Preferences/com.apple.Preview.ViewState.plist”];
    NSData *data = [NSData dataWithContentsOfFile:path];

    NSError *error;
    NSDictionary *propertyList = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListMutableContainers format:0 error:&error];
    propertyList = propertyList[persistentId];
    if (propertyList) {
    data = propertyList[@”Data”];
    propertyList = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListMutableContainers format:0 error:&error];
    if (propertyList) {
    NSLog(@”propertyList: %@”, propertyList);
    }
    else {
    NSLog(@”propertyListWithData error:%@”, error);
    }
    }
    else {
    if (error) {
    NSLog(@”propertyListWithData error:%@”, error);
    }
    NSLog(@”propertyList for %@ is null”, url);
    }
    }
    return 0;
    }

  • 主 資深大佬 : Jooooooooo

    @alaysh 感谢. 我看看.

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具