Skip to content

Commit

Permalink
Improved error message if access not granted
Browse files Browse the repository at this point in the history
  • Loading branch information
RhetTbull committed Jul 13, 2024
1 parent 9333cf3 commit f33332f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 6 additions & 1 deletion osxphotos/cli/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
is_mounted_volume,
is_photoslibrary_path,
pluralize,
terminal,
under_test,
)

Expand Down Expand Up @@ -1691,8 +1692,12 @@ def export_cli(
"Click 'Allow Access to All Photos' in the dialog box to grant access."
)
if not wait_for_photokit_authorization():
if term := terminal():
term = f"terminal app ({term})" if term else "terminal app"
rich_click_echo(
f"[error]Error: could not get authorization to access Photos library.[/]"
f"[error]Error: could not get authorization to access Photos library\n"
f"Please ensure that your {term} is granted access in "
"'System Settings > Privacy & Security > Photos'"
)
return 1

Expand Down
8 changes: 8 additions & 0 deletions osxphotos/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -662,3 +662,11 @@ def download_url_to_temp_dir(url: str) -> str:
# these files will be deleted when the system cleans the temp directory (usually on reboot)
tmpdir = tempdir.tempdir("downloads")
return download_url_to_dir(url, tmpdir, unique=True)


def terminal() -> str:
"""Return name of terminal app that launched the calling script or empty string if terminal cannot be determined.
Note: This only works on macOS
"""
return os.environ.get("TERM_PROGRAM", "")

0 comments on commit f33332f

Please sign in to comment.