0

I'm trying to create an Automator service(in the right click menu) that creates a symlink of the folder/file and moves it to the Dropbox folder. This is what I have right now:

while [ $# -ne 0 ]; do
    ln -s "$1" "$1 symlink"
    mv "$1 symlink" ~/Dropbox/.
    shift
done

However what I want to do is create a folder with the same name ($1). Trying mv "$1 symlink" ~/Dropbox/"$1" doesn't work. I can't seem to figure out how to rename the folder. I tried this, and for some reason, it moved the symlink folder to inside the folder it was symlinking($1).

while [ $# -ne 0 ]; do
    loc = "~/Dropbox"
    ln -s "$1" "$1 symlink"
    mv "$1 symlink" "$loc/$1"
    shift
done
0

This is your current code

while [ $# -ne 0 ]; do
  ln -s "$1" "$1 symlink"     # you create a symlink named "xxx symlink"
  mv "$1 symlink" ~/Dropbox/. # you are moving the symlink into Dropbox folder
  shift
done

you want to symlink to files/directories already in Dropbox, so this has to be done:

while [ $# -ne 0 ]; do
  # you want it to fail if there is a file in dropbox with the same name
  test -e "~/Dropbox/$1" && exit 1

  # order of two lines below is unimportant
  mv "$1" ~/Dropbox/                # move file into dropbox
  ln -s "~/Dropbox/$1" "$1 symlink" # you create a symlink named "xxx symlink"

  shift
done

As for the second part of your question:

However what I want to do is create a folder with the same name ($1). Trying mv "$1 symlink" ~/Dropbox/"$1" doesn't work. I can't seem to figure out how to rename the folder. I tried this, and for some reason, it moved the symlink folder to inside the folder it was symlinking($1).

while [ $# -ne 0 ]; do
  loc = "~/Dropbox"
  ln -s "$1" "$1 symlink"
  mv "$1 symlink" "$loc/$1"
  shift
done

The utility that creates directories is called mkdir. While I can't figure out what folder you want renamed, you do it using mv command. For example mv ~/file ~/Dropbox/backup.thing will rename file file to backup.thing while also moving it between locations.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.