- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在这里找到的这个 AppleScript 可以满足我的需求:
tell application "iTunes"
set matchtrack to tracks in playlist 1 whose persistent ID is "C70EA9CDC276CB6D"
if matchtrack is not {} then
return name of item 1 of matchtrack
else
return "no track found"
end if
end tell
即根据持久ID查找轨道。我正在尝试使用Swift Automation让它在MacOS Cocoa Swift应用程序中工作作为 Apple 事件桥。我可以通过以下方式检索该值:
let trackID = try iTunes.tracks[1].persistentID.get()
我尝试过各种说法。这似乎最有希望:
let trackRow = try iTunes.tracks[ITUItem.persistentID == "C70EA9CDC276CB6D"].get() as ITUItem
当我运行它时,我收到错误:
Instance member 'persistentID' cannot be used on type 'ITUItem'
该框架充其量还处于测试阶段,因此可能是一个错误。还有什么建议可以尝试吗?我想问作者,但找不到联系方式。
这是应用程序生成的 sdef 文件的一部分。
item n : an item
properties
class_ (type, r/o) : the class of the item
container (specifier, r/o) : the container of the item
id (integer, r/o) : the id of the item
index (integer, r/o) : The index of the item in internal application order.
name (text) : the name of the item
persistentID (text, r/o) : the id of the item as a hexadecimal string. This id does not change over time.
properties (record) : every property of the item
Track 是 item 的子类。
当我第一次尝试 @matt 的 ITUIts.persistentID 建议时,它无法编译。我收到错误:
Binary operator '==' cannot be applied to operands of type 'ITUItem' and 'String'
经过一番反复之后,我意识到问题是我缺少导入:
import SwiftAutomation
我最初有它,但不确定我是否需要它,所以我将其注释掉。在我调用这个之前,在没有它的情况下,其他十几个对它的调用都可以正常工作。
最佳答案
使用ITUIts
并摆脱as ITUItem
。所以:
let trackRow = try itunes.tracks[ITUIts.persistentID == "C70EA9CDC276CB6D"].get()
// result will be something along these lines:
// [ITunes().sources.ID(66).libraryPlaylists.ID(93639).fileTracks.ID(95018)]
这里是一个完整的工作测试以及我机器上的结果(当然你的数字会有所不同):
let itunes = ITunes()
let trackID = try itunes.tracks[1].persistentID.get() as String
print("track ID is", trackID)
// track ID is 689006177BB39343
let trackRows = try itunes.tracks[ITUIts.persistentID == trackID].get() as [ITUItem]
if let trackRow = trackRows.first {
print(trackRow)
// ITunes().sources.ID(66).libraryPlaylists.ID(93639).fileTracks.ID(95018)
}
关于macos - 将 AppleScript 转换为 SwiftAutomation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42724421/
还有人在用applescript吗,苹果把文档存档了,好久没更新语言了。这是否意味着语言已死? 最佳答案 自从苹果在 2016 年解散 Mac 自动化团队并(迟迟)解雇了负责它的产品经理以来,整个 A
我无法弄清楚如何检测 AppleScript 中按下的键以及如何延迟直到该键被释放。我想切换缩放,我拥有其他一切(我认为)。这是我当前的代码 on idle set ztoggle to 0
是否可以为使用 AppleScript 创建的应用程序保存某种设置? 设置应在脚本开始时加载,并在脚本结束时保存。 例子: if loadSetting("timesRun") then se
我正在尝试显示我选择的文件的扩展名。我做错了什么? set theFile to (choose file with prompt "Select a file to transfer:")
我正在尝试制作一个将在后台运行并且每周只在特定时间执行一次的 applescript,有什么建议吗? 最佳答案 您可能想要的是 idle handler .首次打开 AppleScript 应用程序时
我希望能够引用与 Controller 位于同一目录中的模型文件。 最初,它们位于项目的根文件夹中,但当它们被编译(使用 osacompile)时,它们都将位于 Controller.scptd/Co
我不知道如何使用 AppleScript,一开始我是如何让我的小 bash 脚本工作的,这超出了我的能力。我目前正在使用 AppleScript 来运行我的 bash 脚本,它工作得非常好。它在下面。
我有一系列 AppleScript 命令需要在一行 AppleScript 中实现。代码如下。 delay 2 tell application "System Events" to keystrok
在 VBA 中,用不同的子字符串替换子字符串非常容易,例如 objMsg.Body = Replace(objMsg.Body, ""在电子邮件正文中使用当前月份。我以前见过与此类似的问题,但它们已经
就目前情况而言,这个问题不太适合我们的问答形式。我们希望答案得到事实、引用资料或专业知识的支持,但这个问题可能会引发辩论、争论、民意调查或扩展讨论。如果您觉得这个问题可以改进并可能重新开放,visit
我已被任命创建一个必须 当网页加载完后,显示一个对话框,显示"The webpage has finished loading." 确定当前正在下载的项目数量 对于数字1,我尝试做if the U
我有一个用于创建作业文件夹的 Applescript。 Applescript 要求提供项目名称和文件夹的存储位置。输入作业名称和文件夹位置后,脚本会创建主文件夹和四个子文件夹。 现在我希望脚本在当前
我有一个字符串,其中包含要删除的非法字符,但我不知道可能存在哪种字符。 我建立了一个我不希望被过滤的字符列表,并建立了这个脚本(来自我在网络上找到的另一个脚本)。 on clean_string(Th
我很困惑 - 我已经用谷歌搜索了一个小时,并尝试了大约十种不同形式的 set posixDirectory to POSIX path of (parent of (path to aFile) as
我在 Automator 中有一个小的 applescript: do shell script "osascript ~/Focus-On.scpt" delay 60 do shell scrip
我想打开一个默认为应用程序设置文件夹的文件夹: /Users/XXX/Library/Application Support/Tunnelblick/Configurations 我不想“硬编码”“X
我试图找出最前面的应用程序 x 是什么,运行脚本,然后使用 applescript 将 x 设置为最前面的应用程序。 tell application "System Events" set
有一个 AppleScript 方法: on displayError(theErrorMessage) display dialog theErrorMessage return "
我正在尝试编写一个脚本来记录当前应用程序、切换到另一个应用程序、执行一些任务并返回到原始应用程序。这就是我所拥有的 set currentApp to my getCurrentApp() activ
我正在尝试根据其文本使用 AppleScript 选择大纲的特定行。 这是我正在考虑的(但不起作用): repeat with aRow in rows of outline 1 of scroll
我是一名优秀的程序员,十分优秀!