• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Relative-Alias Constructor Script – was memory lapse
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Relative-Alias Constructor Script – was memory lapse


  • Subject: Relative-Alias Constructor Script – was memory lapse
  • From: Christopher Stone <email@hidden>
  • Date: Thu, 13 Apr 2017 14:36:18 -0500

Hey Folks,

The easiest way to make path strings is to write scripts that create them from the selection in the Finder.

I've been doing this for a couple of decades now and have scripts that create aliases, Relative-aliases, Posix-Paths (quoted or unquoted), $HOME-Based-Posix-Paths (quoted or unquoted).

Each one of these is bound to some variant of <cmd-key(s)>-P in the Finder with FastScripts.

So I'm only a few keystrokes away from any type of path string I need for scripting.

Appended is my Relative-Alias Constructor Script, which has saved me much work and aggravation over many years.

--
Best Regards,
Chris

------------------------------------------------------------------------------
# Auth: Christopher Stone
# dCre: 2012/09/22 00:36
# dMod: 2014/09/23 21:40
# Appl: Finder
# Task: Create relative alias(es) to selected Finder item(s) and copy to the Clipboard.
#     : If nothing is selected then the insertion location is used.
# Deps: Uses only OSX components.
# Tags: @Applescript, @Finder, @Alias, @Path, @Reference, @Relative
------------------------------------------------------------------------------
--» PROPERTIES
------------------------------------------------------------------------------
property pathToSpec : {application support, applications folder, desktop, desktop pictures folder, documents folder, downloads folder, favorites folder, Folder Action scripts, fonts, help, home folder, internet plugins, keychain folder, library folder, modem scripts, movies folder, music folder, pictures folder, preferences, printer descriptions, public folder, scripting additions folder, scripts folder, shared documents, shared libraries, sites folder, startup disk, startup items, system folder, system preferences, temporary items, trash, users folder, utilities folder, workflows folder}
------------------------------------------------------------------------------
--» GLOBALS
global expandedPathTo
------------------------------------------------------------------------------

try

    

    set clipboardList to {}
    set expandedPathTo to {}

    

    repeat with i in pathToSpec
        set end of expandedPathTo to path to (get contents of i) from user domain
    end repeat

    

    set AppleScript's text item delimiters to return
    set expandedPathTo to paragraphs of (expandedPathTo as text)

    

    tell application "Finder"
        set fileList to selection as alias list
        if length of fileList = 0 then
            set fileList to target of front window as alias as list
        end if
    end tell

    

    if fileList = {} then error "No items were selected in the Finder!"

    

    set AppleScript's text item delimiters to ":"

    

    repeat with i in fileList
        set end of clipboardList to makeRelativeAlias(i)
    end repeat

    

    set AppleScript's text item delimiters to return

    

    set the clipboard to (clipboardList as text)

    

on error e number n
    stdErr(e, n, true, true) of me
end try

------------------------------------------------------------------------------
--» HANLDERS
------------------------------------------------------------------------------
on makeRelativeAlias(_item)
    global expandedPathTo, pathToSpec
    set _item to _item as text
    set _len to (length of (text items of _item))
    repeat with i from _len to 1 by -1
        set _path to ((text items 1 thru i of _item) as text) & ":"
        if _path is in expandedPathTo then
            repeat with idx from 1 to (length of expandedPathTo)
                if (item idx of expandedPathTo) = _path then
                    set refFldr to "path to " & (item idx of pathToSpec) as text
                    set diskLocalRef to ("alias " & ("(" & "(" & refFldr & " as text) & ") & "\"" & (text items (i + 1) thru -1 of _item) as text) & "\")"
                    try
                        run script diskLocalRef
                    on error
                        set refFldr to refFldr & " from user domain"
                        set diskLocalRef to ("alias " & ("(" & "(" & refFldr & " as text) & ") & "\"" & (text items (i + 1) thru -1 of _item) as text) & "\")"
                        try
                            run script diskLocalRef
                        on error e
                            error e
                        end try
                    end try

                    

                    return diskLocalRef

                    

                end if
            end repeat
        end if
    end repeat
end makeRelativeAlias
------------------------------------------------------------------------------

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

  • Prev by Date: Re: memory lapse
  • Next by Date: Applescript Users List Archives Back Up
  • Previous by thread: Re: memory lapse
  • Next by thread: Applescript Users List Archives Back Up
  • Index(es):
    • Date
    • Thread