Skip to content

Commit

Permalink
create-desktop-shortcut@anaximeno: Version 1.6.0 (#416)
Browse files Browse the repository at this point in the history
* chore: Fallback to $HOME/Desktop if xdg-user-dir not available

* chore: Remove hard dependency on xdg-user-dir

* chore: Add check to guarantee consistency with check script

* chore: Update shortcut creation verification

* chore: Bump version
  • Loading branch information
anaximeno authored Jun 25, 2024
1 parent 635b7bb commit 95b36c5
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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=<create-desktop-shortcut@anaximeno/action.py "%F">
Conditions=exec <create-desktop-shortcut@anaximeno/check.sh "%P">;
Extensions=any;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -107,14 +107,22 @@ 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!")
exit(1)

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()
Original file line number Diff line number Diff line change
@@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
"uuid": "create-desktop-shortcut@anaximeno",
"name": "Create Desktop Shortcut Action",
"author": "anaximeno",
"version": "1.5.0"
"version": "1.6.0"
}

0 comments on commit 95b36c5

Please sign in to comment.