diff --git a/create-desktop-shortcut@anaximeno/create-desktop-shortcut@anaximeno.nemo_action.in b/create-desktop-shortcut@anaximeno/create-desktop-shortcut@anaximeno.nemo_action.in index 56163c0b..c7f29500 100644 --- a/create-desktop-shortcut@anaximeno/create-desktop-shortcut@anaximeno.nemo_action.in +++ b/create-desktop-shortcut@anaximeno/create-desktop-shortcut@anaximeno.nemo_action.in @@ -2,7 +2,7 @@ _Name=Create a desktop shortcut _Comment=Create a shortcut of the selected items on the Desktop folder Icon-Name=emblem-symbolic-link -Dependencies=xdg-user-dir;python3;bash; +Dependencies=python3;bash; Exec= Conditions=exec ; Extensions=any; diff --git a/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/action.py b/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/action.py index 5f9e0467..44b86624 100755 --- a/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/action.py +++ b/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/action.py @@ -13,7 +13,7 @@ from helpers import log -class CreateDesktopShortcut: +class CreateDesktopShortcutAction: def __init__(self, desktop_folder: str, items: list[Path]) -> None: self._win_icon = aui.get_action_icon_path(text.UUID) self._override_on_file_exists = None @@ -68,7 +68,7 @@ def link_shortcut_to_item(self, item: Path) -> tuple[Path, bool]: if item.exists(): shortcut.symlink_to(item.resolve(), target_is_directory=item.is_dir()) - return (shortcut, True) + return (shortcut, shortcut.is_symlink()) else: log(f"Error: couldn't create shortcut for {item.name!r}" ", not found!") return (shortcut, False) @@ -107,8 +107,16 @@ def parse_item(item: str) -> str: log("Error: no files provided to create a desktop shortcut") exit(1) - result = subprocess.run(["xdg-user-dir", "DESKTOP"], stdout=subprocess.PIPE) - desktop = result.stdout.decode("utf-8").replace("\n", "") + desktop = "" + + try: + result = subprocess.run(["xdg-user-dir", "DESKTOP"], stdout=subprocess.PIPE) + desktop = result.stdout.decode("utf-8").replace("\n", "") + except Exception as e: + log("Exception:", e) + + if not desktop or not os.path.exists(desktop): + desktop = os.path.join(os.environ.get("HOME", ""), "Desktop") if not os.path.exists(desktop) or not os.path.isdir(desktop): log("Error: XDG User Dir 'DESKTOP' not found or invalid!") @@ -116,5 +124,5 @@ def parse_item(item: str) -> str: items = [Path(parse_item(item)) for item in sys.argv[1:]] - action = CreateDesktopShortcut(desktop_folder=desktop, items=items) + action = CreateDesktopShortcutAction(desktop_folder=desktop, items=items) action.run() diff --git a/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/check.sh b/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/check.sh index 195d7309..661a44ae 100755 --- a/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/check.sh +++ b/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/check.sh @@ -1,7 +1,19 @@ #!/bin/bash -ACTION_DIR=$(echo $1 | sed 's/\\//g') -DESKTOP=$(xdg-user-dir DESKTOP) +ACTION_DIR="$(echo $1 | sed 's/\\//g')" +DESKTOP="$HOME/Desktop" + +if command -v xdg-user-dir &>/dev/null; then + if [[ -d "$(xdg-user-dir DESKTOP)" ]]; then + DESKTOP="$(xdg-user-dir DESKTOP)" + fi +fi + +# Don't show the action if the desktop folder does not +# exist or was not found. +if [[ ! -d $DESKTOP ]]; then + exit 1 +fi # Don't show the action in the context menu, # when we are inside the desktop folder. diff --git a/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/metadata.json b/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/metadata.json index 9169dda6..52f6d99e 100644 --- a/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/metadata.json +++ b/create-desktop-shortcut@anaximeno/files/create-desktop-shortcut@anaximeno/metadata.json @@ -3,5 +3,5 @@ "uuid": "create-desktop-shortcut@anaximeno", "name": "Create Desktop Shortcut Action", "author": "anaximeno", - "version": "1.5.0" + "version": "1.6.0" }