Applescript在文件夹中搜索带有关键字的照片



我想写一个Applescript来搜索照片应用程序中由多个条件返回的照片布尔"one_answers"搜索,例如两个关键字,或专辑位置和关键字。对于上下文,在脚本的后面,我将要求脚本将脚本返回的照片复制到脚本创建的相册中。

Photos AppleScript字典有一个搜索命令,但它只响应文本字符串。似乎没有办法将搜索细化到一个特定的文件夹,或其他搜索条件。

我想知道是否有人知道如何搜索可以约束为两个标准的布尔值?

我是一个新的Applescript感谢任何帮助!

tell application "Photos"
set Srchres to search for "Defined Keyword" in album "Test album"
end tell

照片。应用程序不提供对执行搜索的能力命令在特定的相册。因此,对于您的目的,这个命令将是绝对无用的。

相反,您需要使用,其条款。注意,您应该提供对专辑的完整引用。遵循文件夹和相册的结构在你的Photos.app.
tell application "Photos" to tell album "Test album"
media items whose name contains "Defined Keyword"
end tell

如果我理解正确的话,您需要通过名称中的子字符串搜索媒体元素. 如果您希望通过其中的关键字搜索媒体元素,然后使用以下脚本之一代替第一个脚本:

要按关键字搜索媒体项目,应该使用,其从句也是。注意关键字是字符串的列表(总是)。另外,请注意,您应该按照Photos.app中文件夹和相册的结构提供对相册的完整引用。

这里是搜索的例子,它适用于我的照片。app (Catalina OS):

tell application "Photos"
set Srchres to media items of ¬
(album "Untitled Album" of folder "Untitled Folder2" of folder "Robert") ¬
whose keywords is {"Alexandra", "Untitled Album"}
end tell
--> Result: {media item id "0425380C-2C79-422F-90F8-0DFAB4FF3389/L0/001" of album id "F37876B4-6C89-4B78-90E8-78FF9287E199/L0/040" of folder id "22697ACA-E9AA-4720-BD03-8DF8B6D7E9DA/L0/020" of folder id "C8E0E9FC-57EB-4219-8EAB-BA4B3F34B5DC/L0/020"}

如果您只想搜索某个关键字对于关键字列表,您应该使用"repeat loop";方法:

set mediaItems to {}
tell application "Photos"
tell album "Untitled Album" of folder "Untitled Folder2" of folder "Robert"
repeat with mediaItem in (get media items)
if "Alexandra" is in (get keywords of mediaItem) then
set end of mediaItems to contents of mediaItem
end if
end repeat
end tell
end tell
return mediaItems
--> Result: {media item id "0425380C-2C79-422F-90F8-0DFAB4FF3389/L0/001" of album id "F37876B4-6C89-4B78-90E8-78FF9287E199/L0/040" of folder id "22697ACA-E9AA-4720-BD03-8DF8B6D7E9DA/L0/020" of folder id "C8E0E9FC-57EB-4219-8EAB-BA4B3F34B5DC/L0/020"}

处理程序形式中的最后一个脚本:

on searchByKeyword:theKeyword inAlbum:albumReference
set mediaItems to {}
tell application "Photos" to tell albumReference
repeat with mediaItem in (get media items)
if theKeyword is in (get keywords of mediaItem) then
set end of mediaItems to contents of mediaItem
end if
end repeat
end tell
return mediaItems
end searchByKeyword:inAlbum:
tell application "Photos" to set albumReference to a reference to album "Untitled Album" of folder "Untitled Folder2" of folder "Robert"
my searchByKeyword:"Alexandra" inAlbum:albumReference
--> Result: {media item id "0425380C-2C79-422F-90F8-0DFAB4FF3389/L0/001" of album id "F37876B4-6C89-4B78-90E8-78FF9287E199/L0/040" of folder id "22697ACA-E9AA-4720-BD03-8DF8B6D7E9DA/L0/020" of folder id "C8E0E9FC-57EB-4219-8EAB-BA4B3F34B5DC/L0/020"}

最新更新