• 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(es) to Clipboard
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Relative Alias(es) to Clipboard


  • Subject: Relative Alias(es) to Clipboard
  • From: Christopher Stone <email@hidden>
  • Date: Sat, 29 Jun 2013 20:11:30 -0500

Hey Folks,

I rewrote my relative-alias script 'Path { Alias-Relative of Selection to Clipboard }.scpt' today to handle multiple items selected in the Finder.  (Previously it could only manage a single selected item.)

I've been using this convention for aliases for a long time, but because it's not exactly convenient to write  the reference-form I'd get lazy and just use my plain alias script all too often.

Unfortunately the last time I rebuilt a system from scratch I had broken aliases everywhere, so I vowed to do better.

It get's tiresome manually manufacturing relative-aliases, so of course I eventually wrote a script to do the heavy lifting for me - run from FastScripts with a keyboard shortcut - with the result placed on the clipboard ready for pasting into an Applescript.

I have similar scripts that create plain aliases and posix-paths.

--
Best Regards,
Chris


------------------------------------------------------------------------------------------------
# Auth: Christopher Stone <email@hidden>
# dCre: 2012-09-22 : 00:36
# dMod: 2013-06-29 : 19:17
# Appl: Finder
# Task: Create relative alias(es) to selected Finder item(s) and copy to the Clipboard.
# Deps: Uses only OSX components.
# Tags: @Applescript, @Finder, @Alias, @Path, @Reference, @Relative
------------------------------------------------------------------------------------------------
--» 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
-------------------------------------------------------------------------------------------
--» 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, 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}
-------------------------------------------------------------------------------------------
--» MAIN
-------------------------------------------------------------------------------------------
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)

  

  # Use 'SystemUIServer' if you don't have FastScripts.
  tell application "FastScripts" to activate --» •• { Work around Lion/ML Finder-selection bug. } ••
  # tell application "SystemUIServer" to activate

  

  tell application "Finder"
    activate --» •• { Work around Lion/ML Finder-selection bug. } ••
    set _sel to selection as alias list
    if _sel = {} then error "No items were selected in the Finder!"
  end tell

  

  set AppleScript's text item delimiters to ":"

  

  repeat with i in _sel
    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
  beep
  set e to e & return & return & "Num: " & n
  tell me to set dDlg to display dialog e with title "ERROR!" buttons {"Cancel", "Copy", "OK"} default button "OK"
  if button returned of dDlg = "Copy" then set the clipboard to e
end try

------------------------------------------------------------------------------------------------

 _______________________________________________
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: which is better: applescript "move" command or do shell script mv….?
  • Next by Date: Applescript to print Odd Pages only
  • Previous by thread: Re: getting time to next Time Machine backup and other information?
  • Next by thread: Applescript to print Odd Pages only
  • Index(es):
    • Date
    • Thread