1

The problem: Using dropbox at my work, my colleagues can't follow shortcuts I create. PS: I use "shortcut" (what Windows calls them) and "alias" (the Mac nomenclature) interchangeably here.

The reason it doesn't work is that the shortcuts are tied to my specific user folder: ("C:\Users\MyUserFolderName\Company Dropbox...").

I can manually edit the properties section of each alias I create and replace "C:\Users\MyUserFolderName" with "%USERPROFILE%" (example: "%USERPROFILE%\Company Dropbox..." However, that is tedious.

I often want to make aliases from multiple files, in which case I have to open up each of them and change the target. How can I force windows to automatically replace my user folder with "%USERPROFILE%"?

Or, failing that, How can I use Autohotkey to create a right-click menu option that creates shortcuts and automatically replaces my user folder with "%USERPROFILE%"?

Research so far:

  1. I looked at Using relative paths for Windows shortcuts. However, the most upvoted answer there was to use a utility called "Relative", and this the utility doesn't appear to use the %USERPROFILE% (it uses "%windir% instead).
  2. I looked at How to make Excel use relative paths in external workbook links, but it doesn't address the alias-creation process.
Josh
  • 159

1 Answers1

0

Here's something you could try...

If you run it in AutoHotkey it will just hang around and wait for you to open the properties for a shortcut that you've created. Once it detects that you've opened Shortcut Properties, it will then check to see if the path includes your hardcoded user profile path that Windows populates by default, and if so, will replace the hardcoded path with %USERPROFILE%.

The usage for this would be to create your shortcuts as you normally would, and then open the properties box for each one that you want to update. Since the update process is relatively painless and auto-saves the new path, this may take some of the drain out of your current process, even though it's not a custom shell-extension with a right-click option etc.

If you find that you need to pause the script temporarily, you would also be able to do that via the standard Tray Menu options once it's running.

; Auto-replace shortcut links with %USERPROFILE%

SetTitleMatchMode, 2 EnvGet, myUserProfile, UserProfile Loop {

WinWaitActive, Shortcut Properties ahk_class #32770

nowID:=WinExist("A") ; Save the ID of the current window for use below if needed

ControlGetText, myTarget, Edit2
If InStr(myTarget, myUserProfile) {

    newTarget := "%USERPROFILE%" . SubStr(myTarget, StrLen(myUserProfile)+1)
    ControlSetText, Edit2, %newTarget%

    ; hardcode this to False if you don't want the dialog box to auto-save
    If autoSave:=True    
        SendInput, {Enter}

    ToolTip, Successfully updated shortcut link to use UserProfile...
    Sleep 1500
    ToolTip
}

WinWaitNotActive, ahk_id %nowID%  ; don't re-execute immediately if we're not auto-saving

}

JJohnston2
  • 1,929