Make alias and move file

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:
------------------------------------------------------------