Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: lets play a game

  1. #1
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    lets play a game

    the mission is simple, check a directory for content, if there is content, replace a line in a file.
    i'm thinking maybe script run with cron?

    how would you do it?

    what i'm actually doing is making a trash app/launcher just for the heck of it. i just want a working trash icon on my dash to dock.

    the line i want to swap back & fourth
    Code:
    Icon=user-trash
    to
    Icon=user-trash-full
    my trash.desktop
    Code:
    [Desktop Entry]
    Type=Application
    Name=Trash
    Comment=Trash
    Icon=user-trash
    Exec=nautilus /home/user/.local/share/Trash
    Categories=Utility;
    Actions=trash;
    
    [Desktop Action trash]
    Name=Empty Trash
    Exec=/home/user/Documents/trash.sh
    my trash.sh
    Code:
    #!/bin/sh
    rm -rf /home/user/.local/share/Trash/*
    Screenshot from 2018-05-05 17-49-33.jpgScreenshot from 2018-05-05 17-49-27.jpg

    truth is i haven't done scripting in ages, i'm trying to remember, but my brains just not there. i'm not sure what to use.
    maybe something like:
    Code:
    #!/bin/sh
    path=/home/user/.local/share/Trash
    1=Icon=user-trash
    2=Icon=user-trash-full
    icon=/home/user/.local/share/applications/trash.desktop
    
    if [ ! "$(ls -A $path)" ]
    then
        sed -i "/$1/c $2" $icon
    else
        sed -i "/$2/c $1" $icon
    fi

  2. #2
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: lets play a game

    working script:

    Code:
    #!/bin/sh
    cp /home/user/.local/share/applications/trash.desktop /home/user/.local/share/applications/trash.desktop.bak
    path=/home/user/.local/share/Trash/files
    icon=/home/user/.local/share/applications/trash.desktop
    icon2=/home/user/.local/share/applications/trash.desktop.bak
    
    if [ "$(ls -A $path)" ]; then
        sed 's/user-trash/user-trash-full/' $icon2 > $icon
    else
        sed 's/user-trash-full/user-trash/' $icon2 > $icon
    fi

  3. #3
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: lets play a game

    alright, i got working trash on my dash to dock.
    i'm sure there are other ways to do it, this is the way i did it trying to keep it simple with the same results every time, doesn't spawn the same process over & over, doesn't drive the memory up. doesn't screw up the trash.desktop, which is why i dropped sed for cat.
    anyways enjoy.

    updated i just use 3 files now

    i guess i'll star with the scripts.

    trash.sh -r <-checks for trash & changes icon
    trash.sh -e <- empties trash & changes icon back.
    trash.sh -d <-add this to startup

    trash.sh
    Code:
    #!/bin/bash
    path=/home/user/.local/share/Trash/files
    icon=/home/user/.local/share/applications/trash.desktop
    
    while getopts "red" opt; do
    	case $opt in
        r)
    	if [ "$(ls -A $path)" ]; then
    		echo -e '[Desktop Entry]\nType=Application\nName=Trash\nComment=Trash\nIcon=user-trash-full\nExec=nautilus /home/user/.local/share/Trash/files\nCategories=Utility;\nActions=trash;\n\n[Desktop Action trash]\nName=Empty Trash\nExec=/home/user/Documents/trash.sh -e\n' > $icon
    	fi
    	;;
        e)
    	rm -rf /home/user/.local/share/Trash/files/* && rm -rf /home/user/.local/share/Trash/info/* && echo -e '[Desktop Entry]\nType=Application\nName=Trash\nComment=Trash\nIcon=user-trash\nExec=nautilus /home/user/.local/share/Trash/files\nCategories=Utility;\nActions=trash;\n\n[Desktop Action trash]\nName=Empty Trash\nExec=/home/user/Documents/trash.sh -e\n' > $icon
    	;;
        d)
    	while sleep 60; do (/home/user/Documents/trash.sh -r &) ; done
    	;;
      esac
    done
    trash.desktop <-this is the applet/application that you would add to dock
    Code:
    [Desktop Entry]
    Type=Application
    Name=Trash
    Comment=Trash
    Icon=user-trash
    Exec=nautilus /home/user/.local/share/Trash/files
    Categories=Utility;
    Actions=trash;
    
    [Desktop Action trash]
    Name=Empty Trash
    Exec=/home/user/Documents/trash.sh -e
    Attached Images Attached Images
    Last edited by kerry_s; May 7th, 2018 at 09:36 PM.

  4. #4
    Join Date
    Nov 2007
    Beans
    Hidden!

    Re: lets play a game

    I am a tad OCD when it comes to my Recycle Bin. I always delete completely, never send anything there
    Gaming on Linux has never been better - Check out Proton on Steam (great user made Proton Database) and Lutris
    How to ask questions the smart way

  5. #5
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: lets play a game

    Quote Originally Posted by thenailedone View Post
    I am a tad OCD when it comes to my Recycle Bin. I always delete completely, never send anything there
    i use to do that, but now i'm old & make more mistakes. my attention span is all over the place sometimes.

  6. #6
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: lets play a game

    i updated post #3 cause i changed from cat file > file to echo > file, getting rid of the 2 spare copies, now i'm down to 4 files to have a working trash icon.

    i'd like to combine trash.sh & trash-icon.sh to 1 file if i can.

  7. #7
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: lets play a game

    okay i combined trash.sh & trash-icon.sh in to 1 file. i'll fix post #3 with new file.

    trash.sh -r <-checks for trash & changes icon
    trash.sh -e <- empties trash & changes icon back.

    Code:
    #!/bin/bash
    path=/home/user/.local/share/Trash/files
    icon=/home/user/.local/share/applications/trash.desktop
    
    while getopts "re" opt; do
    	case $opt in
        r)
    	if [ "$(ls -A $path)" ]; then
    		echo -e '[Desktop Entry]\nType=Application\nName=Trash\nComment=Trash\nIcon=user-trash-full\nExec=nautilus /home/user/.local/share/Trash/files\nCategories=Utility;\nActions=trash;\n\n[Desktop Action trash]\nName=Empty Trash\nExec=/home/user/Documents/trash.sh\n' > $icon
    	fi
    	;;
        e)
    	rm -rf /home/user/.local/share/Trash/files/* && rm -rf /home/user/.local/share/Trash/info/* && echo -e '[Desktop Entry]\nType=Application\nName=Trash\nComment=Trash\nIcon=user-trash\nExec=nautilus /home/user/.local/share/Trash/files\nCategories=Utility;\nActions=trash;\n\n[Desktop Action trash]\nName=Empty Trash\nExec=/home/user/Documents/trash.sh\n' > $icon
    	;;
      esac
    done

  8. #8
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: lets play a game

    i went ahead & added the watch.sh into trash.sh to just make it 2 files for a working trash can app.
    Screenshot from 2018-05-07 10-38-49.jpgScreenshot from 2018-05-07 10-39-47.jpgScreenshot from 2018-05-07 10-39-40.jpg

  9. #9
    Join Date
    Nov 2007
    Beans
    Hidden!

    Re: lets play a game

    Nice project, well executed
    Gaming on Linux has never been better - Check out Proton on Steam (great user made Proton Database) and Lutris
    How to ask questions the smart way

  10. #10
    Join Date
    Jul 2006
    Location
    Here
    Beans
    11,187

    Re: lets play a game

    Quote Originally Posted by thenailedone View Post
    Nice project, well executed
    thank you, i was just bored & it didn't seem like it would be to complicated. i still had to rtfm cause there are a lot of ways of doing it, i just wanted simple so any 1 could use it just changing the "user" name & maybe path.

    i suppose i could make that easier using $user at the top.

    i'll fix it later, i gotta go get my weekly blood test, i so hate the smell of hospitals now.

Page 1 of 2 12 LastLast

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •