Make alias and move file

OK folks, now I get to offer something constructive. Passing this on in case It helps. I wanted to know how to move a file using Finder. It turns out that you can use a keystroke which is far easier than writing a script.

I am working on a project which requires reviewing a large number of documents then moving relevant found documents to my project folder while I put together a final PDF for project output. To do this I need to figure a way to keep all my files where they are parked, then to pull instances of each relevant file into the project folder.

I wrote a small macro that made an alias of a file that, after I previewed It and determined It needed to be in the project folder, then moved the alias to a project folder with a single keystroke.

Because make alias works differently with single files than with multiple files I decided to make this work for only one file at a time. Single “make alias” (command+L) leaves the file name highlighted for renaming and I didn’t want to command copy text - alter the name, I wanted to copy the file location. One of my KM keystroke used to fix that was the escape key. Doing multiple files into aliases, does not leave the file name ready to type in, so this step is unnecessary.

When a file is highlighted you copy it using command+C, then you open a different location and hit command+option+V. The file appears in the new location and is gone from where you copied It. The file is now moved.

Type the ⌘L Keystroke
Pause for 1.5 Seconds
Type the Escape Keystroke
Type the ⌘C Keystroke
Pause for 1.5 Seconds
Open ‘/Users//Documents/Organization/VA IG VRE/Active Case’
Pause for 1.5 Seconds
Type the ⌥⌘V Keystroke

Hey levelbest ,

This macro requires Yosemite or higher.

  • Copy your file(s) and/or folder(s) in the Finder to the clipboard with Cmd-C.
  • Navigate to your preferred destination.
  • Activate the macro.

Symlinks will be created in the destination folder for all files/folders in the clipboard.

(Thanks to Shane Stanley for his help with the ASObjC.)

-Chris

Create Symlinks in Front Finder Window from Files Copied to Clipboard.kmmacros (4.3 KB)

2 Likes

Thank you for making these macros! I found your macro ccstone very useful. I have two questions, maybe someone in the forum knows:

  1. I use Path Finder instead of Finder, currently does not work with Path Finder, tried to modify the script but cannot get it to work (I’m a KM/programmer novice). Anyone know how to adapt it to work with Path Finder?
  2. Could it be changed to paste OS X alias instead of Symlinks?

Hey @cands,

You can't. Path Finder has no concept of insertion location.

It could be made to work IF there was a selection in the place you wanted to paste the aliases.

Path Finder does understand the selection, and from that we can extract the current insertion location.

Yes.

-Chris

Thanks for the explanations, from which I think I would be able to modify the script to suit my workflow. However, using Finder and Symlinks is fine as well, thanks again.

Hey @cands

Here’s a working script that will create aliases from items copied in Path Finder into the pane where you have a selection.

There MUST be a selection in the Path Finder pane you want to paste to, AND that pane MUST be active.

-Chris

------------------------------------------------------------
# Auth: Christopher Stone <scriptmeister@thestoneforge.com>
#     : Liberal help with ASObjC provided by Shane Stanley.
# dCre: 2015/08/07 20:00
# dMod: 2016/03/26 12:50
# Appl: Path Finder
# Task: Paste Aliases of files copied to the clipboard in front Path Finder window.
# Libs: None
# Osax: None
# Tags: @Applescript, @Script, @Path_Finder
------------------------------------------------------------

use framework "Foundation"
use framework "AppKit"
use scripting additions

------------------------------------------------------------
tell application "Path Finder"
	set pfSelection to the selection
	if pfSelection ≠ {} then
		set theItem to POSIX path of (item 1 of pfSelection)
	else
		error "No selection was made in Path Finder!"
	end if
end tell
set theItem to alias POSIX file theItem
tell application "Finder"
	set selectionParentFolder to (parent of theItem) as alias
end tell
set pasteAliasDest to POSIX path of selectionParentFolder
------------------------------------------------------------

set pb to current application's NSPasteboard's generalPasteboard()
set theURLs to pb's readObjectsForClasses:{current application's class "NSURL"} options:(missing value)
set theFileManager to current application's NSFileManager's defaultManager()
set destFolderURL to current application's class "NSURL"'s fileURLWithPath:pasteAliasDest
set theCount to theURLs's |count|()

repeat with i from 1 to theCount
	
	set thisURL to (theURLs's objectAtIndex:(i - 1))
	set theName to thisURL's lastPathComponent() as text
	set newPath to pasteAliasDest & theName
	
	(my createAlias:newPath pointingTo:(thisURL as text))
	
end repeat

------------------------------------------------------------
# Creates an alias file at the provided path
on createAlias:aFileOrPath pointingTo:originalFileOrPath
	set theAliasURL to my makeURLFromFileOrPath:aFileOrPath
	set originalURL to my makeURLFromFileOrPath:originalFileOrPath
	set {theData, theError} to originalURL's bookmarkDataWithOptions:(current application's NSURLBookmarkCreationSuitableForBookmarkFile) includingResourceValuesForKeys:(missing value) relativeToURL:(missing value) |error|:(reference)
	if theData is missing value then error (theError's |localizedDescription|() as text)
	set {theResult, theError} to current application's class "NSURL"'s writeBookmarkData:theData toURL:theAliasURL options:0 |error|:(reference)
	if not (theResult as boolean) then error (theError's |localizedDescription|() as text)
end createAlias:pointingTo:
------------------------------------------------------------
on makeURLFromFileOrPath:theFileOrPathInput
	-- make it into a Cocoa object for easier comparison
	set theFileOrPath to item 1 of (current application's NSArray's arrayWithObject:theFileOrPathInput)
	if (theFileOrPath's isKindOfClass:(current application's NSString)) as boolean then
		if (theFileOrPath's hasPrefix:"/") as boolean then -- full POSIX path
			return current application's class "NSURL"'s fileURLWithPath:theFileOrPath
		else if (theFileOrPath's hasPrefix:"~") as boolean then -- POSIX path needing ~ expansion
			return current application's class "NSURL"'s fileURLWithPath:(theFileOrPath's |stringByExpandingTildeInPath|())
		else -- must be HFS path
			return current application's class "NSURL"'s fileURLWithPath:(POSIX path of theFileOrPathInput)
		end if
	else if (theFileOrPath's isKindOfClass:(current application's class "NSURL")) as boolean then -- happens with files and aliases in 10.11
		return theFileOrPath
	else -- must be a file or alias
		return current application's class "NSURL"'s fileURLWithPath:(POSIX path of theFileOrPathInput)
	end if
end makeURLFromFileOrPath:
------------------------------------------------------------

Thank you very much for adapting the script! It now works like a charm with Path Finder and alias files! This script makes it so much easier to work with alias.