0

iPhoto 表示它必须重建其数据库,然后之前的手动事件排序全部搞砸了。

我尝试从备份中恢复较旧的数据库,但 iPhoto 会再次重建,再次将其搞砸。

能够从 iPhoto 库备份中的文件中提取事件的原始顺序AlbumData.xml(遗憾的是,编辑此文件不会修复顺序)。

我找不到用 AppleScript 或其他任何东西更改手动事件顺序的方法(也许你可以用 SQLite 以某种方式做到这一点)。

但编辑 iPhoto 事件标题似乎更可行,添加数字前缀(“1. 我的第一个事件”、“2. 我的第二个事件”),然后按标题而不是手动对事件进行排序。这似乎也不那么脆弱了。可以将新事件命名为“1.1 我的中等事件”以介于两者之间。

但要实现这一点,如果我可以以编程方式批量编辑标题会很方便。那可能吗?我在 AppleScript Dictionary 中看不到任何有用的东西。

4

1 回答 1

0

我开始手动为它们编号,然后我意识到 iPhoto 有相当可编写脚本的键盘快捷键:编辑一个事件标题时,您可以跳到下一个事件标题。所以我编写了那个脚本。

这是 Ruby(我选择的武器)和 AppleScript 的一个非常丑陋和骇人听闻的组合,它是为解决我的特定问题而编写的,但它可能很好地说明了如何做到这一点:

def osascript(cmd)
  system "osascript", "-e", cmd
end

def assign(number, name)
  `echo | pbcopy` #  clear out clipboard in case the title is empty and the cmd+c fails
  osascript %{tell app "System Events" to keystroke "c" using command down}  # copy
  actual_name = `pbpaste`
  name_was_empty = actual_name.to_s.chop.empty?  # names generated from dates may show as empty when you try to edit them

  if (actual_name == name) || name_was_empty
    puts "go on"
    osascript %{tell app "System Events" to keystroke (ASCII character 28)}  # left
    osascript %{tell app "System Events" to keystroke "#{number}. "}
    osascript %{tell app "System Events" to keystroke #{name.inspect}} if name_was_empty
    osascript %{tell app "System Events" to keystroke tab}
  else
    puts "Got: #{actual_name.inspect} but expected #{name.inspect} (number: #{number})"
    osascript %{tell app "iPhoto" to display dialog "Not the name I expected. Bailing!"}
    exit 1
  end
end

osascript %{tell app "iPhoto" to activate}
osascript %{tell app "iPhoto" to display dialog "Click the first event title and wait…"}
sleep 3

# You would probably loop over some data structure here.
assign(1, "My first event")
assign(2, "My second event")
# …

也可作为 Gist 使用。

于 2014-02-08T09:24:53.857 回答