Reference
PhotosLibrary
Source code in photoscript/__init__.py
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 |
|
favorites
property
Album object for the Favorites album
frontmost
property
True if Photos.app is front most app otherwise False
hidden
property
True if Photos is hidden (or not running), False if Photos is visible
name
property
name of Photos.app
running
property
True if Photos is running, otherwise False
selection
property
List of Photo objects for currently selected photos or [] if no selection
version
property
version of Photos.app as str
__init__()
create new PhotosLibrary object and launch Photos
Source code in photoscript/__init__.py
60 61 62 63 |
|
activate()
activate Photos.app
Source code in photoscript/__init__.py
65 66 67 |
|
album(*name, uuid=None, top_level=False)
Album instance by name or id
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
name of album |
()
|
|
uuid
|
id of album |
None
|
|
top_level
|
if True, searches only top level albums; default = False |
False
|
Returns:
Type | Description |
---|---|
Album object or None if album could not be found |
Must pass only name or id but not both. If more than one album with same name, returns the first one found.
Source code in photoscript/__init__.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
|
album_names(top_level=False)
List of album names in the Photos library
Parameters:
Name | Type | Description | Default |
---|---|---|---|
top_level
|
if True, returns only top-level albums otherwise also returns albums in sub-folders; default is False |
False
|
Source code in photoscript/__init__.py
257 258 259 260 261 262 263 |
|
albums(top_level=False)
list of Album objects for all albums
Source code in photoscript/__init__.py
302 303 304 305 |
|
create_album(name, folder=None)
creates an album
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
name of new album |
required | |
folder
|
'Folder'
|
Folder object in which to create new album. If None, creates top-level album. Default is None. |
None
|
Returns:
Type | Description |
---|---|
'Album'
|
Album object for newly created album |
Source code in photoscript/__init__.py
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 |
|
create_folder(name, folder=None)
creates a folder
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of new folder |
required |
folder
|
'Folder'
|
Folder object in which to create the new folder. If None, creates top-level folder. Default is None. |
None
|
Returns:
Type | Description |
---|---|
'Folder'
|
Folder object for newly created folder |
Source code in photoscript/__init__.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 |
|
delete_album(album)
deletes album (but does not delete photos in the album)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
album
|
'Album'
|
an Album object for album to delete |
required |
Source code in photoscript/__init__.py
333 334 335 336 337 338 339 |
|
delete_folder(folder)
Deletes folder (and all its sub-folders and albums)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder
|
'Folder'
|
a Folder object for folder to delete |
required |
Notes
On macOS 10.15 & above, only top-level folders can be deleted. Sub-folders cannot be deleted due to a bug in Photos' AppleScript implementation.
Source code in photoscript/__init__.py
487 488 489 490 491 492 493 494 495 496 497 498 |
|
folder(name=None, path=None, uuid=None, top_level=True)
Folder instance by name or uuid
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of folder, e.g. "My Folder" |
None
|
path
|
list[str]
|
path of folder as list of strings, e.g. ["My Folder", "Subfolder"] |
None
|
uuid
|
str
|
id of folder, e.g. "F1234567-1234-1234-1234-1234567890AB" |
None
|
top_level
|
if True, only searches top level folders by name; default is True |
True
|
Returns:
Type | Description |
---|---|
Folder object or None if folder could not be found |
Notes
Must pass one of path, name, or uuid but not more than one If more than one folder with same name, returns first one found.
Source code in photoscript/__init__.py
341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 |
|
folder_by_path(folder_path)
Return folder in the library by path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path
|
list of folder names in descending path order, e.g. ["Folder", "SubFolder1", "SubFolder2"] |
required |
Returns:
Type | Description |
---|---|
Folder object for folder at folder_path or None if not found |
Source code in photoscript/__init__.py
383 384 385 386 387 388 389 390 391 392 393 |
|
folder_names(top_level=False)
List of folder names in the Photos library
Parameters:
Name | Type | Description | Default |
---|---|---|---|
top_level
|
if True, returns only top-level folders otherwise also returns sub-folders; default is False |
False
|
Source code in photoscript/__init__.py
265 266 267 268 269 270 271 |
|
folders(top_level=True)
list of Folder objects for all folders
Source code in photoscript/__init__.py
395 396 397 398 |
|
hide()
Tell Photos to hide its window
Source code in photoscript/__init__.py
105 106 107 |
|
import_photos(photo_paths, album=None, skip_duplicate_check=False)
import photos
Parameters:
Name | Type | Description | Default |
---|---|---|---|
photo_paths
|
list of file paths to import as str or pathlib.Path |
required | |
album
|
optional, Album object for album to import into |
None
|
|
skip_duplicate_check
|
if True, Photos will not check for duplicates on import, default is False. |
False
|
Returns:
Type | Description |
---|---|
list of Photo objects for imported photos |
If you attempt to import a duplicate photo and skip_duplicate_check != True,
Photos will block with drop-down sheet until the user clicks "Cancel, Import, or Don't Import."
Source code in photoscript/__init__.py
227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 |
|
make_album_folders(album_name, folder_path)
Make album in a folder path. If either the album or any component of the folder path doesn't exist, it will be created. If album or folder path does exist, no duplicate is created. Folder path is created recursively if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
album_name
|
name of album to create. If album already exists, returns existing album. |
required | |
folder_path
|
list of folder names in descending path order, e.g. ["Folder", "SubFolder1", "SubFolder2"]. |
required |
Returns:
Type | Description |
---|---|
Album object. |
Source code in photoscript/__init__.py
457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
|
make_folders(folder_path)
Recursively makes folders and subfolders. Works similar to os.makedirs_. If any component of folder_path already exists, does not raise error.
.. _os.makedirs: https://docs.python.org/3/library/os.html#os.makedirs
Parameters:
Name | Type | Description | Default |
---|---|---|---|
folder_path
|
list of folder names in descending path order, e.g. ["Folder", "SubFolder1", "SubFolder2"] |
required |
Returns:
Type | Description |
---|---|
Folder object for the final sub folder |
Source code in photoscript/__init__.py
426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 |
|
open(library_path, delay=10)
open a library and wait for delay for user to acknowledge in Photos
Source code in photoscript/__init__.py
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
|
photos(search=None, uuid=None, range_=None)
Returns a generator that yields Photo objects for media items in the library.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
search
|
optional text string to search for (returns matching items) |
None
|
|
uuid
|
optional list of UUIDs to get |
None
|
|
range
|
optional list of [start, stop] sequence of photos to get |
required |
Returns:
Type | Description |
---|---|
Generator that yields Photo objects |
Note: photos() returns a generator instead of a list because retrieving all the photos from a large Photos library can take a very long time--on my system, the rate is about 1 per second; this is limited by the Photos AppleScript interface and I've not found anyway to speed it up. Using a generator allows you process photos individually rather than waiting, possibly hours, for Photos to return the results.
range works like python's range function. Thus range=[0,4] will return Photos 0, 1, 2, 3; range=[10] returns the first 10 photos in the library; range start must be in range 0 to len(PhotosLibrary())-1, stop in range 1 to len(PhotosLibrary()). You may be able to optimize the speed by which photos are return by chunking up requests in batches of photos using range, e.g. request 10 photos at a time.
Source code in photoscript/__init__.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
|
quit()
quit Photos.app
Source code in photoscript/__init__.py
69 70 71 |
|
Photo
Source code in photoscript/__init__.py
988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 |
|
albums
property
list of Album objects for albums photo is contained in
altitude
property
GPS altitude of photo in meters
date
property
writable
date of photo as timezone-naive datetime.datetime object
description
property
writable
description of photo
favorite
property
writable
return favorite status (boolean)
filename
property
filename of photo
height
property
height of photo in pixels
keywords
property
writable
list of keywords for photo
location
property
writable
The GPS latitude and longitude, in a tuple of 2 numbers or None. Latitude in range -90.0 to 90.0, longitude in range -180.0 to 180.0.
name
property
writable
name of photo (read/write)
title
property
writable
title of photo (alias for name)
uuid
property
UUID of Photo
width
property
width of photo in pixels
duplicate()
duplicates the photo and returns Photo object for the duplicate
Source code in photoscript/__init__.py
1178 1179 1180 1181 |
|
export(export_path, original=False, overwrite=False, timeout=120, reveal_in_finder=False)
Export photo
Parameters:
Name | Type | Description | Default |
---|---|---|---|
photo
|
Photo object to export |
required | |
export_path
|
path to export to |
required | |
original
|
if True, export original image, otherwise export current image; default = False |
False
|
|
overwrite
|
if True, export will overwrite a file of same name as photo in export_path; default = False |
False
|
|
timeout
|
number of seconds to wait for Photos to complete export before timing out; default = 120 |
120
|
|
reveal_in_finder
|
if True, will open Finder with exported items selected when done; default = False |
False
|
Returns:
Type | Description |
---|---|
List of full paths of exported photos. There may be more than one photo exported due |
|
to live images and burst images. |
Note: Photos always exports as high-quality JPEG unless original=True. If original=True, will export all burst images for burst photos and live movie for live photos. If original=False, only the primary image from a burst set will be exported for burst photos and the live movie component of a live image will not be exported, only the JPEG component.
Source code in photoscript/__init__.py
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 |
|
spotlight()
spotlight the photo in Photos
Source code in photoscript/__init__.py
1183 1184 1185 |
|
Album
Source code in photoscript/__init__.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 |
|
name
property
writable
name of album (read/write)
parent
property
Return parent Folder object
parent_id
property
parent container id
title
property
writable
title of album (alias for Album.name)
uuid
property
UUID of Album (read only)
add(photos)
add photos from the library to album
Parameters:
Name | Type | Description | Default |
---|---|---|---|
photos
|
list of Photo objects to add to album |
required |
Returns:
Type | Description |
---|---|
list of Photo objects for added photos |
Source code in photoscript/__init__.py
671 672 673 674 675 676 677 678 679 680 681 682 |
|
export(export_path, original=False, overwrite=False, timeout=120, reveal_in_finder=False)
Export photos in album to path
Parameters:
Name | Type | Description | Default |
---|---|---|---|
photo
|
Photo object to export |
required | |
export_path
|
path to export to |
required | |
original
|
if True, export original image, otherwise export current image; default = False |
False
|
|
overwrite
|
if True, export will overwrite a file of same name as photo in export_path; default = False |
False
|
|
timeout
|
number of seconds to wait for Photos to complete export (for each photo) before timing out; default = 120 |
120
|
|
reveal_in_finder
|
if True, will open Finder with exported items selected when done; default = False |
False
|
Returns:
Type | Description |
---|---|
List of full paths of exported photos. There may be more than one photo exported due |
|
to live images and burst images. |
Note: Photos always exports as high-quality JPEG unless original=True. If original=True, will export all burst images for burst photos and live movie for live photos. If original=False, only the primary image from a burst set will be exported for burst photos and the live movie component of a live image will not be exported, only the JPEG component.
Source code in photoscript/__init__.py
699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 |
|
import_photos(photo_paths, skip_duplicate_check=False)
import photos
Parameters:
Name | Type | Description | Default |
---|---|---|---|
photos
|
list of file paths to import |
required | |
skip_duplicate_check
|
if True, Photos will not check for duplicates on import, default is False |
False
|
Returns:
Type | Description |
---|---|
list of Photo objects for imported photos |
Source code in photoscript/__init__.py
684 685 686 687 688 689 690 691 692 693 694 695 696 697 |
|
path_str(delim='/')
Return internal library path to album as string. e.g. "Folder/SubFolder/AlbumName"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
delim
|
character to use as delimiter between path elements; default is "/" |
'/'
|
Source code in photoscript/__init__.py
651 652 653 654 655 656 657 658 659 660 661 662 663 664 |
|
photos()
list of Photo objects for photos contained in album
Source code in photoscript/__init__.py
666 667 668 669 |
|
remove(photos)
Remove photos from album. Note: Photos does not provide a way to remove photos from an album via AppleScript. This method actually creates a new Album with the same name as the original album and copies all photos from original album with exception of those to remove to the new album then deletes the old album.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
photos
|
list of Photo objects to remove |
required |
Returns:
Type | Description |
---|---|
new Album object for the new album with photos removed. |
Source code in photoscript/__init__.py
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 |
|
remove_by_id(photo_ids)
Remove photos from album. Note: Photos does not provide a way to remove photos from an album via AppleScript. This method actually creates a new Album with the same name as the original album and copies all photos from original album with exception of those to remove to the new album then deletes the old album.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
photo_ids
|
list of photo ids to remove |
required |
Returns:
Type | Description |
---|---|
new Album object for the new album with photos removed. |
Source code in photoscript/__init__.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 |
|
spotlight()
spotlight the album in Photos
Source code in photoscript/__init__.py
791 792 793 |
|
Folder
Source code in photoscript/__init__.py
799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 |
|
albums
property
list of Album objects for albums contained in folder
id
property
ID of folder
idstring: str
property
idstring of folder
name
property
writable
name of folder (read/write)
parent
property
Return parent Folder object
parent_id
property
parent container id string
subfolders
property
list of Folder objects for immediate sub-folders contained in folder
title
property
writable
title of folder (alias for Folder.name)
uuid
property
UUID of folder
__init__(uuid=None, path=None, idstring=None)
Create a Folder object; only one of path, uuid, or idstring should be specified
The preferred method is to use the path argument or idstring to specify the folder as this is much faster than using uuid. The uuid argument is listed first for backwards compatibility.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path
|
list[str] | None
|
list of folder names in descending order from parent to child: ["Folder", "SubFolder"] |
None
|
uuid
|
str | None
|
uuid of folder: "E0CD4B6C-CB43-46A6-B8A3-67D1FB4D0F3D/L0/020" or "E0CD4B6C-CB43-46A6-B8A3-67D1FB4D0F3D" |
None
|
idstring
|
str | None
|
idstring of folder: "folder id("E0CD4B6C-CB43-46A6-B8A3-67D1FB4D0F3D/L0/020") of folder id("CB051A4C-2CB7-4B90-B59B-08CC4D0C2823/L0/020")" |
None
|
Source code in photoscript/__init__.py
800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 |
|
album(name)
Return Album object contained in this folder for album named name or None if no matching album
Source code in photoscript/__init__.py
938 939 940 941 942 |
|
create_album(name)
Creates an album in this folder
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
str
|
name of new album |
required |
Returns:
Type | Description |
---|---|
'Album'
|
Album object for newly created album |
Source code in photoscript/__init__.py
961 962 963 964 965 966 967 968 969 970 |
|
create_folder(name)
creates a folder in this folder
Returns:
Type | Description |
---|---|
'Folder'
|
Folder object for newly created folder |
Source code in photoscript/__init__.py
972 973 974 975 976 977 978 |
|
folder(name)
Folder object for first subfolder folder named name.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name
|
name of folder to to return |
required |
Returns:
Type | Description |
---|---|
Folder object for first subfolder who's name matches name or None if not found |
Source code in photoscript/__init__.py
950 951 952 953 954 955 956 957 958 959 |
|
path()
Return list of Folder objects this folder is contained in. path()[0] is the top-level folder this folder is contained in and path()[-1] is the immediate parent of this folder. Returns empty list if folder is not contained in another folders.
Source code in photoscript/__init__.py
923 924 925 926 927 928 929 930 |
|
path_str(delim='/')
Return internal library path to folder as string. e.g. "Folder/SubFolder"
Parameters:
Name | Type | Description | Default |
---|---|---|---|
delim
|
character to use as delimiter between path elements; default is "/" |
'/'
|
Source code in photoscript/__init__.py
908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
|
spotlight()
spotlight the folder in Photos
Source code in photoscript/__init__.py
980 981 982 |
|