Results 1 to 10 of 33
I wonder if anyone is here. This solution looked quite promising but I tried to go to the aforementioned jesgue.homelinux.org site and that site is dead.
I've been doing various ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
- 12-10-2010 #1Just Joined!
- Join Date
- Nov 2010
- Location
- Philippines
- Posts
- 27
Convert Windows shortcuts into Linux links
I wonder if anyone is here. This solution looked quite promising but I tried to go to the aforementioned jesgue.homelinux.org site and that site is dead.
I've been doing various Google searches on this for about a week and I've looked through everything from blogs, Linux Questions Forum, Ubuntu forum, etc ... It's just ocured to me to type a Google search I hadn't tried before "script convert .lnk to link" and this site came up.
Could anyone help me please. I'm sure I have a thousand .lnk files to try to convert. Even if I could convert them in batches of ten at a time would be a HUGE help. I'm using Ubuntu 10.04 Lucid and running BASH of course.
- 12-10-2010 #2Linux Guru
- Join Date
- Nov 2007
- Location
- Crdoba (Spain)
- Posts
- 1,513
Yes. It's dead for good. The server crashed and I have no time (and no reason) to put it back again. Luckily, I found a copy of the file on my local ~/bin. I paste it below after a couple of corrections.
I didn't review it throughout-fully, so, as always, do your own checks.Code:#!/bin/bash ###################################################################### # # # lnk2symlink by jesus.guerrero.botella at gmail dot com, # # search for windows .lnk files on a given directory, and creates # # symlinks according to the info contained on those files # # # # This script is provided without any kind of implicit or explicit # # guarantee, and is licensed under the GNU General Public License v3 # # or later if available. More about licenses on the following URL: # # # # http://www.gnu.org/licenses/licenses.html # # # ###################################################################### VERSION=20101210 PROGRAM_NAME=$(basename $0) DELETE_LNK=0 die() { case $1 in non_linkable_fs) echo "The target filesystem doesn't support symlinks." exit 11 ;; ln_error) echo "Undefined error while symlinking." exit 10 ;; *) echo "Undefined error." exit 20 ;; esac } show_help() { echo "$PROGRAM_NAME v$VERSION" echo "Search for windows .lnk files and creates linux symlinks according" echo "to the info within those .lnk files." echo echo "Usage: " echo " $PROGRAM_NAME [-d|--do] [directory]" echo echo "Where the optional parameter [directory] is a directory where to look" echo "for .lnk files, and -d|--do is a parameter to actually do the work." echo "By default, $PROGRAM_NAME will not do anything, but just output WHAT" echo "would be done if -d|--do is used." echo echo "Parameters:" echo " -d, --do" echo " Do the real work." echo " -h, --help" echo " Show this help text." echo " -e, --erase, --del, --delete" echo " Delete de .lnk files after doing the work. These imply --do." echo } case $1 in -h|--help|"") show_help exit 0 ;; -d|--do) DO_WORK=1 DIR="$2" ;; -e|--erase|--del|--delete) DELETE_LNK=1 DO_WORK=1 DIR="$2" ;; *) DO_WORK=0 DIR="$1" ;; esac TEST_FILE="$DIR/test-$RANDOM$RANDOM$RANDOM$RANDOM" ln -s "$HOME" "$TEST_FILE" > /dev/null 2>&1 || die non_linkable_fs rm -f "$TEST_FILE" echo "Specified directory: $DIR" echo "Finding files, this may take a while..." find "$DIR" -iname '*.lnk' | while read LNK_FILE do echo echo "Processing file: $LNK_FILE" echo "================================================================================" CANDIDATE_STRING=$(strings "$LNK_FILE" | grep ':\\') LINUX_PATH="$(echo $CANDIDATE_STRING | \ sed -e 's#.*\:\\#'"$HOME"'\/.wine\/drive_c\/#' | \ sed -e 's#\\#\/#g')" SYMLINK_NAME="${LNK_FILE/.lnk/}" if [ ! -L "$SYMLINK_NAME" ] then if [ -r "$SYMLINK_NAME" ] then echo "File with the same name detected, but it's not a symlink." echo "I will add a RANDOM suffix to the symlink name." SYMLINK_NAME="${SYMLINK_NAME}-${RANDOM}" fi if [ $DO_WORK -eq "1" ] then echo "Running: ln -s $LINUX_PATH $SYMLINK_NAME" ln -s "$LINUX_PATH" "$SYMLINK_NAME" || die else echo "This is what WOULD be done:" echo "ln -s $LINUX_PATH $SYMLINK_NAME" fi else echo "$SYMLINK_NAME do exist, and it's a symlink, skipping." fi if [ $DELETE_LNK -eq "1" ] then rm -f "$LNK_FILE" fi done
- 12-10-2010 #3Just Joined!
- Join Date
- Nov 2010
- Location
- Philippines
- Posts
- 27
Thank you thank you thank. I will 'so' be taking a look at this and trying it out at the beginning of the week.
I'm winding down for the day (I'm on the other side of the world). But even 'if' it doesn't work out of the box it will give me something I can start from and tweak. If it works out of the box already then I will start posting it at the other ten places that I looked where 'so' many people were having this problem and couldn't' find a solution.
But of course the other folks were (like me) initially thinking about it from a more difficult starting point. I was initially wondering how could I get Ubuntu to simply open up and follow these Windows shortcuts. Then after several hours I and looking at what was there I thought "hmm; what about a script that converted them to symlinks.".
Again thanks.
- 12-10-2010 #4Linux Guru
- Join Date
- Nov 2007
- Location
- Crdoba (Spain)
- Posts
- 1,513
Ugh! Another thread has been split. Which rendered useless the link in the notification I got via e-mail with your response. So I had to dive into the forum to search for it. Thanks dog, I know they do that kind of thing, otherwise I wouldn't have been able to answer you, just because someone decided that your answer was better split into a new thread, rather than just leaving it in the thread it belonged to, inside a meaningful context. Oh, well...
It really bothers me the tradition they have in this forum to systematically close old threads just because they are old even when they have something useful to say. Maybe I am being too picky about such a silly thing, but I stopped posting here long ago partly because of things like this.
The moderation team should stop and think about it for a moment: this is just like having to fork "ls" because it has been around for many decades. I say there's no need to do so because "ls" works ok just like it worked the first day. You can update it, add functionality to it just like you add posts to a thread that's as valid today as it was two years ago. But killing it to create a new "ls" doesn't make any sense. The same goes for a document (the old thread) that's still valid. I can't understand this age-phobia.
Smart persons don't put old things aside just because they are old. Now the thread is split in two parts, being this new thread out of context. But well, it's 1:30 AM around here, too late for me to fix the world right now.
So, back to the (now halved) topic:
You are welcome.
Based on the core of my script, you could design a new one that could open the URL or program that the lnk file points to (using xdg-open, for example), then just associate the .lnk extension in your file browser to your shiny new script.I'm winding down for the day (I'm on the other side of the world). But even 'if' it doesn't work out of the box it will give me something I can start from and tweak. If it works out of the box already then I will start posting it at the other ten places that I looked where 'so' many people were having this problem and couldn't' find a solution.
But of course the other folks were (like me) initially thinking about it from a more difficult starting point. I was initially wondering how could I get Ubuntu to simply open up and follow these Windows shortcuts. Then after several hours I and looking at what was there I thought "hmm; what about a script that converted them to symlinks.".
Of course, just using my script periodically (or when needed) to convert the files to symlinks could also get the job done.
The choice is yours
- 12-11-2010 #5Just Joined!
- Join Date
- Nov 2010
- Location
- Philippines
- Posts
- 27
I agree. People shouldn't put old things aside because they are old :-) ... DOS is still pretty cool too. I rarely use it anymore but every once it a while still helps me out.
Thanks for the further tips. You sound like you know quite a bit. I'm still a newbie as far as Linux goes. Been a tech for sixteen years and played with Linux from time to time but it wasn't until I found Lucid that I became lucid <he he>. Now it's the only thing on my machine.
I'll be working on this .lnk thing until I can get it to work. Might take a while since I'm not a programmer. But I know how to look at code, basically figure out what it's doing, and post for help. This whole experience will probably teach me a lot and I look forward to it.
- 12-11-2010 #6Linux Guru
- Join Date
- Nov 2007
- Location
- Crdoba (Spain)
- Posts
- 1,513
Feel free to poke me in this same thread if you need some help.
Luck in your quest
- 12-13-2010 #7Just Joined!
- Join Date
- Nov 2010
- Location
- Philippines
- Posts
- 27
Hmm. So far doesn't do anything. I viewed the permissions to make sure it was executable before I tried it. I copied it into "/home/scribe/.gnome2/nautilus-scripts" so I can right-click on .lnk files to convert them.
Here is what I've tried so far:
1) Right-Clicking directly on a .lnk file
2) tried right clicking on a director that contact 'one' symlink since the comments on your script said "search for windows .lnk files on a given directory"
3) Also attempted to "right-click" in the white space in the "given directory" and choosing the script to see if it would work that way.
Then, since I'm a newbie I tried some things that I think probably won't matter but I wanted to exercise due diligence:
1) noticed I had named the script with spaces so I renamed it "lnk2symlink"
2) directed "chmod 755" at the file again on a command prompt.
3) wondered if the problem didn't have something to do with the lnk file being on my external drive so I copied the test lnk file to sda1 (which is Ext4) but that didn't do anything either.
Here are the contents of the lnk file in question (as viewed in notepad):
Code:L F *`^ !Yd 8 * PO :i +00 /G:\ * 1 :G I :Gw< I 0 1 :G TIM :Gw< T i m V 1 :# GOTTCH~1.SER : :#: G O T T C H A B u s . S e r v H 1 :# GOTTIT~1 0 :#: G o t t i t D u n n 6 1 :# ADMIN " :#: A d m i n P 1 :# LEGALD~1 8 :#: L e g a l D e p a r t m e n t m - l m: G:\I\Tim\GOTTCHA Bus. Serv\Gott it Dunn\Admin\Legal Department D . . \ . . \ . . \ . . \ . . \ G O T T C H A B u s . S e r v \ G o t t i t D u n n \ A d m i n \ L e g a l D e p a r t m e n t
~ No error messages or output of any kind were given at any point.
- 12-13-2010 #8Linux Guru
- Join Date
- Nov 2007
- Location
- Crdoba (Spain)
- Posts
- 1,513
By default, the script only works in informative mode, you need to pass it a parameter so it does the real work. See the help in the script. Maybe that's the problem.
I can't help you with nautilus specific stuff because I know nothing about nautilus (other than you can click icons on it). But I'd try running it from a terminal window so you can see the error messages, if any.
- 12-13-2010 #9Just Joined!
- Join Date
- Nov 2010
- Location
- Philippines
- Posts
- 27
Went out to get a late lunch and figured this part out when I came back by searching the net. I came back to the forum trying to "beat you to the punch". I just got as far as running "./lnk2symlink" from the command line just now.
I'll try "./lnk2symlink -d" in just a minute or two
- 12-13-2010 #10Just Joined!
- Join Date
- Nov 2010
- Location
- Philippines
- Posts
- 27
Ok just issued both of these commands on the test directory that I copied to sda1:
./lnk2symlink -d Legal Department.lnk
and
./lnk2symlink -d "Legal Department.lnk"
and both errors came up with "The target filesystem doesn't support symlinks."
And then [progress]
Instead of issuing the command 'on' the .lnk file I issued the command on the directory itself. Ok just call me slow
This time it 'did' create a broken symlink. I looked at the properties of the broken symlink and it's pointing at "/home/scribe/.wine/drive_c/I/Tim/GOTTCHA Bus. Serv/Gott it Dunn/Admin/Legal Department"
Neat trick. I'll try to do this on the test directory as it sits on the external drive and see if I come up with different properties.


Reply With Quote

