【发布时间】:2020-06-01 21:08:33
【问题描述】:
我在一个目录结构中有数百张图片,有时我想一张一张地查看它们以找到我想要的那张。
我想把每一个都打开,如果不是我想要的,关闭它并查看下一个,单击鼠标或在终端窗口中输入一个字母的命令。在执行一个applescript告诉Preview关闭最前面的窗口后,是否可以打开一个文件并保留控制权。当我尝试这个时,预览保持活动状态,我的脚本暂停,我需要 cmd-tab 返回 iTerm 窗口以使其继续。在对预览执行“告诉”之前,我尝试在 applescript 中设置超时,但这没有用。有没有解决的办法?这是我当前的 ruby 脚本:
#!/usr/bin/env ruby
require 'find'
def osascript(script)
system 'osascript', *script.split(/\n/).map { |line| ['-e', line] }.flatten
end
file_paths = []
Find.find('.') do |path|
file_paths << path if path =~ /.*\.png$/
end
file_paths.each do |f|
system "open '#{f}'"
decision = gets.chomp
if decision.eql? "s" then
exit
end
osascript <<-END
tell application "Preview"
close window 1
end tell
END
end
【问题讨论】:
标签: ruby applescript