• Apfeltalk ändert einen Teil seiner Allgemeinen Geschäftsbedingungen (AGB), das Löschen von Useraccounts betreffend.
    Näheres könnt Ihr hier nachlesen: AGB-Änderung
  • Viele hassen ihn, manche schwören auf ihn, wir aber möchten unbedingt sehen, welche Bilder Ihr vor Eurem geistigen Auge bzw. vor der Linse Eures iPhone oder iPad sehen könnt, wenn Ihr dieses Wort hört oder lest. Macht mit und beteiligt Euch an unserem Frühjahrsputz ---> Klick

[Fotos] Applescript: Mediatheken in der Familie Synchronisieren

cusertrumpl

Thurgauer Weinapfel
Registriert
04.02.08
Beiträge
999
Ich habe ein Skript geschrieben, mit dem ich prüfen kann welche Fotos von mir, meine Frau noch nicht hat und umgekehrt. Da wir nur die meisten, aber nicht alle Ordner synchronisieren wollen, gibt es ein Album, über das Bilder ausgeschlossen werden können.

Gerne möchte ich es euch zur Verfügung stellen und freue mich über Kommentare.

Funktionsweise:
  1. Auf beiden Rechnern mit dem Skripteditor eine App mit dem angegebenen Code erstellen.
  2. Die App auf Rechner A ausführen und eine Datei speichern (evtl. gleich in geteiltem Ordner)
  3. Auf Rechner B ein Album "Nicht teilen" anlegen für die Bilder, die A nicht braucht.
  4. Die Datei mit der gleichen App öffnen (Drag 'n Drop).
Das Skript legt jetzt ein Album an, dass alle Fotos enthält, die A vielleicht gerne möchte. A kann sich jetzt an B's Rechner setzten und sich die Fotos holen, die er mag. Die restlichen schiebt er ins Album "Nicht teilen" fürs nächste mal.


Anmerkung: Das Skript vergleicht die Bilder nur basierend auf dem Aufnahmedatum. Haben Bilder kein Aufnahmedatum (WhatsApp) wird das Änderungsdatum verwendet.

AppleScript:
on AppleScriptDateToString(b)
    set Y to year of b
    set M to Twodigits(month of b as integer)
    set D to Twodigits(day of b)
    set hh to Twodigits(hours of b)
    set mm to Twodigits(minutes of b)
    set ss to Twodigits(seconds of b)
    return Y & "-" & M & "-" & D & " " & hh & ":" & mm & ":" & ss as text
end AppleScriptDateToString

on Twodigits(a)
    return (characters -2 thru -1 of (("0" & a) as text)) as text
end Twodigits

on run
    set theFile to open for access (choose file name) with write permission
    tell application "Photos"
        set theDates to date of media items
        set theoutputString to ""
        repeat with theDate in theDates
            set t to my AppleScriptDateToString(theDate) & "
"
            --log t
            set theoutputString to theoutputString & t
        end repeat
        write theoutputString to theFile
    end tell
    close access theFile
end run
on open dateien
    set datei to item 1 of dateien
    set alredyThereDates to paragraphs of (read file datei)
    tell application "Photos"
        set exAlbum to item 1 of (albums whose name is "Nicht teilen")
        set excludeIds to id of (media items of exAlbum)
        set theDates to date of media items
        set theIds to id of media items
        set theCounter to 0
        set theAlbum to make new album named "Evtl. teilen"
        repeat with theId in theIds
            set theCounter to theCounter + 1
            if excludeIds does not contain theId then
                set theDate to item theCounter of theDates
                set t to my AppleScriptDateToString(theDate)
                if alredyThereDates does not contain t then
                    add {item theCounter of media items} to theAlbum
                    log "add"
                else
                    log "already there"
                end if
            else
                log "excluded"
            end if
        end repeat
    end tell
end open