本文介绍了OSX 照片、Applescript:循环播放时刻?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 AppleScript 非常陌生,但我已经广泛(多年)使用其他脚本语言,所以对游戏来说并不是全新的.我刚刚遗憾地告别了 Aperture,并将我将近 100K 的数字图像导入到照片中(所以我也是照片的新手).我想为查找图像制作一个合理的结构,即

I am very new to AppleScript but have worked extensively (for years) with other scripting languages, so not entirely new to the game. I have just sadly said goodbye to Aperture and imported my nearly 100K digital images into Photos (so I'm also brand new to Photos). I would like to make a sane structure for finding images, i.e.

Folders named for Year (e.g. 2004)
contain Folders named for Month (e.g. 05)
contain Albums named for each day for which there are images (e.g. 2004-05-03)
(yes this is basically the Picasa convention, which I am accustomed to and like)

将我的 100K 图像导入照片后,显然成功了,我发现它们在默认情况下被组织到时刻"(即日期)中,但没有分层组织来使浏览更容易,如上所述.所以我想写一个AppleScript来做如下:

Having imported my 100K images into Photos, apparently with success, I find that they are organised by default into "Moments" (i.e. dates), but there is no hierarchical organisation to make browsing easier, as above. So I would like to write an AppleScript to do as follows:

foreach Moment
   parse the date and create folder for year if it does not exist already
   create folder inside year for month if not exists already
   create album inside month for day, if not exists already
   assign all photos in this Moment to that album

看起来很简单,手工制作需要几十个小时:-)所以除非我可以编写脚本,否则永远不会发生.我一直在阅读(看似相当有限的)AppleScript 照片字典,到目前为止还没有看到任何对 Moments 的有用参考,例如如何循环遍历所有列表,查找其中包含的图像列表等.我查看用两个属性定义的对象时刻",ID 和名称;但我在寻找所有 Moments 的主列表或 Moments 的内容时有点挣扎.

Seems simple enough, and it would take tens of hours by hand :-) so never going to happen unless I can script it. I've been reading the (seemingly rather limited) AppleScript dictionary for Photos and so far have not seen any useful reference to Moments, as in how to loop through a list of them all, find list of images contained in one, etc. I see the object "moment" defined with two attributes, ID and name; but I'm floundering around a bit trying to find the master list of all Moments or the contents of Moments.

我有一种感觉,来自熟悉这个应用程序(和 AppleScript)的人的 2 段或一大块示例代码可以为我节省数小时的谷歌搜索.有谁知道如何解决这个问题?

I have a feeling that 2 paragraphs or one chunk of sample code from someone familiar with this app (and with AppleScript) would save me hours of googling. Does anyone know how to go about this?

[更新]

我尝试了 DLing 并为照片安装了一个有前途的脚本库

I have tried DLing and installing a promising script library for Photos

https://photosautomation.com/scripting/script-library.html

但到目前为止还没有能够执行它的任何功能.我也试过对照片最基础的探索命令:

but so far have not been able to get any of its functions to execute. I have also tried the most basic exploratory command to Photos:

tell application "Photos"
    activate
    set moms to the moments of application
    display dialog moms
end tell

并收到一条不太有启发性的错误消息:

and got a not-too-enlightening error message:

error "Can’t get every moment of application." number -1728 from every «class IPmm» of application

推荐答案

我在 Yosemite (10.10.5) 上为 Photos 1.0.1 写了这个,所以它可能需要为你做一些修改,但这是我能做的最好的,希望它将在您的操作系统上运行.我试图为你评论它,这样你就可以看到它在做什么.

I wrote this on Yosemite (10.10.5) for Photos 1.0.1 so it may need some modifications for you, but it's the best I could do, hopefully it will work on your OS. I tried to comment it for you so you'd be able to see what it was doing.

on run
    tell application "Photos"
        set mediaItems to every media item
        repeat with mediaItem in mediaItems
            set mdate to (date of mediaItem) -- get the date of the file
            set yearName to year of mdate as string -- year of the file
            set YrFolder to my yearFolder(yearName) -- make the year folder

            set mmonth to month of mdate -- month of the file
            set monthName to my monthNum(mmonth as string) -- month name as a number
            set SubFold to my subFolder(monthName, YrFolder) -- make the month number folder

            set mday to day of mdate -- day of the file
            set dayName to my dayNum(mday as string) -- get the day as a two digit number
            set albumName to yearName & "-" & monthName & "-" & dayName as string -- create the album name
            set finalAlbum to my makeAlbum(albumName, SubFold) -- make the album

            add {mediaItem} to finalAlbum -- put the item in the album
        end repeat
    end tell

end run


on dayNum(mday)
    if (count of characters in mday) = 1 then
        return "0" & mday as string
    else
        return mday as string
    end if
end dayNum

on monthNum(mmonth)
    if mmonth = "January" then
        set num to "01"
    else if mmonth = "February" then
        set num to "02"
    else if mmonth = "March" then
        set num to "03"
    else if mmonth = "April" then
        set num to "04"
    else if mmonth = "May" then
        set num to "05"
    else if mmonth = "June" then
        set num to "06"
    else if mmonth = "July" then
        set num to "07"
    else if mmonth = "August" then
        set num to "08"
    else if mmonth = "September" then
        set num to "09"
    else if mmonth = "October" then
        set num to "10"
    else if mmonth = "November" then
        set num to "11"
    else if mmonth = "December" then
        set num to "12"
    end if
    return num
end monthNum


on makeAlbum(albName, theFolder)
    tell application "Photos"
        set yrFold to name of parent of theFolder
        if exists container albName of container (name of theFolder) of container yrFold then
            return (container albName of container (name of theFolder) of container yrFold)
        else
            return make new album named albName at theFolder
        end if
    end tell
end makeAlbum


on subFolder(subName, YrFolder)
    tell application "Photos"
        if exists container subName of container (name of YrFolder) then
            return container subName of container (name of YrFolder)
        else
            return make new folder named subName at YrFolder
        end if
    end tell
end subFolder

on yearFolder(yearName)
    tell application "Photos"
        if container named yearName exists then
            return container named yearName
        else
            try
                return make new folder named yearName
            on error
                return ""
            end try
        end if
    end tell
end yearFolder

祝你好运,很想知道它是否适合你.

Best of luck with it, would love to know if it works for you.

这篇关于OSX 照片、Applescript:循环播放时刻?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-06 10:43
查看更多