Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macOS OOP Implementation #15

Merged
merged 28 commits into from
Jul 21, 2021
Merged
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
1251bb5
Add support for Mac OS
williamchange Jun 17, 2021
043bb7f
no_furls function should return a boolean
williamchange Jun 18, 2021
4e01997
Restore check for unsupported platform to keep errors verbose
williamchange Jun 18, 2021
d9b9e3f
Merge branch 'main' of https://github.com/Yeetus3141/ImagePaste into …
williamchange Jun 18, 2021
7f49679
Merge branch 'Yeetus3141-main' into main
williamchange Jun 18, 2021
4a7313a
Follow repository convention
williamchange Jun 18, 2021
7f7d6ca
fix relative imports
williamchange Jun 18, 2021
e3417d1
update .gitignore to include mac's pasteboard modules
williamchange Jun 18, 2021
cc87d18
improve GrabImage return logic
williamchange Jun 18, 2021
654c6b3
Update __init__.py
williamchange Jun 18, 2021
73aa759
Merge branch 'Yeetus3141:main' into main
williamchange Jun 20, 2021
6ca898b
skipping __init__.py when importing pasteboard module
williamchange Jun 20, 2021
8b55457
Merge branch 'Yeetus3141:main' into main
williamchange Jun 20, 2021
79d88ec
Merge branch 'Yeetus3141:main' into main
williamchange Jun 21, 2021
8db7bd6
Add files via upload
b-init Jul 18, 2021
9117fc0
Update CHANGELOG.md
b-init Jul 18, 2021
ffd97dd
Merge branch 'Yeetus3141:main' into main
williamchange Jul 19, 2021
f8cf864
Add mssing execute function call and correctly capturing stdout
williamchange Jul 20, 2021
d631fb1
Fix typo in preferences and add missing execute function call
williamchange Jul 20, 2021
e670d25
Merge branch 'oop-implementation' of github.com:williamchange/ImagePa…
williamchange Jul 20, 2021
f09ca37
merge upstream
williamchange Jul 20, 2021
6754802
Merge pull request #2 from Yeetus3141/oop-implementation
williamchange Jul 20, 2021
74f564f
remove residual files
williamchange Jul 20, 2021
781c47b
Check if file actually get saved instead of checking stderr
williamchange Jul 20, 2021
0579010
Update imagepaste/clipboard/darwin/darwin.py
williamchange Jul 20, 2021
6baefa9
use pasteboard to check for filepaths
williamchange Jul 20, 2021
45346e4
target TIFF when checking clipboard contents via pasteboard
williamchange Jul 21, 2021
c8d41ce
Remove version 1.5.2 in `CHANGELOG.md`
thanhph111 Jul 21, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 14 additions & 18 deletions imagepaste/clipboard/darwin/darwin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,21 @@ def push(cls, save_directory: str) -> DarwinClipboard:
holding the images information.
"""
from os.path import join
from .pasteboard._native import Pasteboard
from os.path import isfile
from .pasteboard import _native as pasteboard

pb = pasteboard.Pasteboard()

# Use Pasteboard to get file URLs from the clipboard
pasteboard = Pasteboard()
urls = pasteboard.get_file_urls()
urls = pb.get_file_urls()
if urls is not None:
filepaths = list(urls)
images = [Image(filepath) for filepath in filepaths]
return cls(Report(6, f"Pasted {len(images)} image files: {images}"), images)

# If no images are found, return a report with no images
contents = pasteboard.get_contents()
if contents == "":
return cls(Report(2))

# Check if clipboard doesn't contain any filepaths
# (e.g. if the clipboard contains just a single image)
commands = [
'((clipboard info) as string does not contain "«class furl»") as string'
]
process = Process(cls.get_osascript_args(commands))
if process.stdout == "true":
# Save an image if it is in the clipboard
contents = pb.get_contents(type=pasteboard.TIFF)
if contents is not None:
filename = cls.get_timestamp_filename()
filepath = join(save_directory, filename)
image = Image(filepath, filename)
Expand All @@ -65,10 +58,13 @@ def push(cls, save_directory: str) -> DarwinClipboard:
"close access pastedImage",
]
process = Process.execute(cls.get_osascript_args(commands))
if process.stderr:
if not isfile(filepath):
return cls(Report(3, f"Cannot save image: {image} ({process.stderr})"))
williamchange marked this conversation as resolved.
Show resolved Hide resolved
if process.stderr:
report = Report(6, f"Saved 1 image: {image} (WARN: {process.stderr})")
return cls(report, [image])
return cls(Report(6, f"Saved and pasted 1 image: {image}"), [image])
return cls(Report(3))
return cls(Report(2))

@classmethod
def pull(cls, image_path: str) -> DarwinClipboard:
Expand All @@ -86,7 +82,7 @@ def pull(cls, image_path: str) -> DarwinClipboard:
"set the clipboard to "
f'(read file POSIX file "{image_path}" as «class PNGf»)'
]
process = Process(cls.get_osascript_args(commands))
process = Process.execute(cls.get_osascript_args(commands))
if process.stderr:
return cls(Report(4, f"Process failed ({process.stderr})"))
image = Image(image_path)
Expand Down