1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2026-03-18 13:11:39 +00:00

Add initial pyobjc version for macOS

This is to help with issue #51.  Will not help in the case of python 2 or
older python 3 version < 3.6.
This commit is contained in:
2021-04-13 22:36:10 -05:00
parent 10c7693d11
commit 530e9b4bc6
4 changed files with 99 additions and 49 deletions

View File

@@ -0,0 +1,29 @@
# Copyright 2017 Virgil Dupras
# This software is licensed under the "BSD" License as described in the "LICENSE" file,
# which should be included with this package. The terms are also available at
# http://www.hardcoded.net/licenses/bsd_license
from Foundation import NSFileManager, NSURL
from .compat import text_type
def check_op_result(op_result):
# First value will be false on failure
if not op_result[0]:
# Error is in third value, localized failure reason matchs ctypes version
raise OSError(op_result[2].localizedFailureReason())
def send2trash(paths):
if not isinstance(paths, list):
paths = [paths]
paths = [
path.decode("utf-8") if not isinstance(path, text_type) else path
for path in paths
]
for path in paths:
file_url = NSURL.fileURLWithPath_(path)
fm = NSFileManager.defaultManager()
op_result = fm.trashItemAtURL_resultingItemURL_error_(file_url, None, None)
check_op_result(op_result)