Tuesday, January 23, 2018

#1 2007-09-10 03:30:15 pm

sprale
Member
From:: Texas
Registered: 2007-06-07
Posts: 131

getPath and goTo apps. Quick and easy location management

One of the features I love about Windows (yes, I said it), is the address bar. You can select, copy paste and type away to your hearts content. Outside of Path Finder, this is not easy in the Mac OS. Maybe 10.5 will fix this oversight... Until then, I (with a more than a bit of help from the forums here) created a pair of apps to ease the task of telling someone where you are working. The idea is that you drop them as apps in your '/Library/Scripts/' folder. Then you drop each on the toolbar of a Finder window, so they become a part of the Finder windows. In a production environment working with many large servers, this is a wonderful way to tell someone where to find a file or folder you have been working on. These two are the latest versions I have, and anyone is more than welcome to use and modify them as they see fit.

Thanks to all the wonderful scripters for the guidance and help. I am really enjoying this journey.

getPath gets the POSIX path of the front window you have open.

Applescript:


tell application "Finder"
   try
       set theSelection to the selection
   on error
       display dialog "You must have something selected and be in list view." buttons {"OK"} default button 1
       error number -128
   end try
   try
       set thePath to theSelection as alias as string
   on error
       display dialog "You must have something selected and be in list view." buttons {"OK"} default button 1
       error number -128
   end try
   set theChosenPath to button returned of (display dialog "Choose HFS (:) or POSIX (/) format?" buttons {"HFS", "POSIX"} default button 1)
   if theChosenPath = "POSIX" then
       set thePOSIXpath to POSIX path of thePath
       set thePOSIXpath to thePOSIXpath
       set the clipboard to thePOSIXpath
   else
       set thePath to thePath
       set the clipboard to thePath
   end if
end tell

goTo opens a new window with the POSIX path you want to go to.

Applescript:


display dialog "Where would you like to go?" default answer "/"
set userInput to text returned of result
try
   set userInput to POSIX file userInput as alias
on error
   display dialog "The path does not exist or there is an extra return at the end of the string." buttons {"Cancel"} default button 1
end try

tell application "Finder"
   activate
   set newWindow to make new Finder window
   set target of newWindow to userInput
end tell

Model: Dual 2.3GHz G5
AppleScript: 2.1.1/Script Debugger 4
Browser: Firefox 2.0.0.6
Operating System: Mac OS X (10.4)

Last edited by sprale (2008-12-08 03:31:21 pm)


Dead-thread Necromancer!


Filed under: Finder

Offline

 

#2 2007-09-10 04:12:16 pm

Mikey-San
Member
Registered: 2005-07-13
Posts: 509

Re: getPath and goTo apps. Quick and easy location management

never had this problem, yo. that path bar in windows explorer is cluttery as well as being confusing for lots of users, too.

command-option-g and the Path button in the finder toolbar work well for me. ditto column view. smile

Offline

 

#3 2007-09-11 01:14:31 am

chrys
Member
From:: McKinney, TX, USA
Registered: 2007-06-26
Posts: 442

Re: getPath and goTo apps. Quick and easy location management

Mikey-San wrote:

command-option-g and the Path button in the finder toolbar work well for me. ditto column view. smile


In case you did not know, command-clicking on the proxy icon or title in the title bar of a Finder window, provides nearly the same functionality as the Path button in Finder's toolbar. Safari also does something similar for URLs.


--
Chris

Offline

 

#4 2007-09-11 08:16:27 am

Qwerty Denzel
Member
Registered: 2005-06-11
Posts: 337

Re: getPath and goTo apps. Quick and easy location management

The basic problem is that there is no easy way to get the working path as text. The points are, however, perfectly valid for the second script.

Here's an altered script to do the copying to the clipboard for you.

Applescript:

tell application "Finder"
   if exists (front Finder window) then
       set thePath to POSIX path of (target of front Finder window as alias)
       display dialog thePath & return & return & "Copy front Finder window path to clipboard?" buttons {"Cancel", "Copy"} default button 2
       set the clipboard to thePath
   end if
end tell


Filed under: Finder

Offline

 

#5 2007-09-11 08:39:33 am

Adam Bell
Administrator
From:: Nova Scotia, Canada
Registered: 2005-10-04
Posts: 4660

Re: getPath and goTo apps. Quick and easy location management

Rather nicely done, QD. I've embroidered it slightly for my own use:

Applescript:

tell application "Finder"
   if exists (front Finder window) then
       if button returned of (display dialog "HFS or POSIX Path?" with title "Path Type" buttons {"Cancel", "HFS Path", "POSIX Path"} default button 3) is "HFS Path" then
           set thePath to (target of front Finder window as alias) as string
       else
           set thePath to POSIX path of (target of front Finder window as alias)
       end if
       display dialog thePath & return & return & "Copy front Finder window target to clipboard?" buttons {"Cancel", "Copy"} default button 2
       set the clipboard to thePath
   end if
end tell


iMac running OS X 10.13.1


Filed under: Finder

Offline

 

#6 2007-09-11 09:11:19 am

sprale
Member
From:: Texas
Registered: 2007-06-07
Posts: 131

Re: getPath and goTo apps. Quick and easy location management

I appreciate all of the wonderful advice on this one. My goal was a way to simplify the process for some users who are not hotkey-friendly. A few of them are midrange users, but most are more creative-types and this dual-purpose script is perfect for them. Now that I have been reminded of the 'go to' command I will probably use it, as it seems to be a bit quicker.

Levon


Dead-thread Necromancer!

Offline

 

#7 2014-03-19 02:30:31 pm

sprale
Member
From:: Texas
Registered: 2007-06-07
Posts: 131

Re: getPath and goTo apps. Quick and easy location management

For anyone interested, here is the latest code I have our users running for these scripts. No changes were necessary from 10.8 to 10.9, but I did find an interesting post at c|net with other alternatives to this. http://reviews.cnet.com/8301-13727_7-57 … 5259999241

getPath:

Applescript:


tell application "Finder"
   try
       set theSelection to the selection
   on error
       display dialog "You must have something selected and be in list view." buttons {"OK"} default button 1
       error number -128
   end try
   try
       set thePath to theSelection as alias as string
   on error
       display dialog "You must have something selected and be in list view." buttons {"OK"} default button 1
       error number -128
   end try
   set theChosenPath to button returned of (display dialog "Choose HFS (:) or POSIX (/) format?" buttons {"HFS", "POSIX"} default button 2)
   if theChosenPath = "POSIX" then
       set thePOSIXpath to POSIX path of thePath
       set thePOSIXpath to thePOSIXpath
       set the clipboard to thePOSIXpath
   else
       set thePath to thePath
       set the clipboard to thePath
   end if
end tell

goTo:

Applescript:


display dialog "Where would you like to go?" default answer "/"
set userInput to text returned of result
try
   set userInput to POSIX file userInput as alias
on error
   display dialog "Path doesn't exist" buttons {"Cancel"} default button 1
end try

tell application "Finder"
   activate
   set newWindow to make new Finder window
   set target of newWindow to userInput
end tell


Dead-thread Necromancer!

Offline

 

#8 2014-03-19 02:55:09 pm

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11483
Website

Re: getPath and goTo apps. Quick and easy location management

This is a version considering multiple selections and "active" error handling without try blocks.
If the user doesn't press the HFS or POSIX button, POSIX will be selected after 2 seconds.
The script is not restricted to list view.

Applescript:


activate application "SystemUIServer" -- works around a Finder selection bug
tell application "Finder"
   activate
   set theSelection to (get selection)
   if theSelection is {} then display dialog "You must have something selected" buttons {"Cancel"} default button 1
   set {button returned:pathMode, gave up:gaveUP} to display dialog "Choose HFS (:) or POSIX (/) format?" buttons {"Cancel", "HFS", "POSIX"} default button "POSIX" giving up after 2
end tell
set resultList to {}
repeat with oneFile in theSelection
   set hfsPath to oneFile as text
   if pathMode is "POSIX" or gaveUP then
       set end of resultList to POSIX path of hfsPath
   else
       set end of resultList to hfsPath
   end if
end repeat

set {TID, text item delimiters} to {text item delimiters, return}
set resultList to resultList as text
set text item delimiters to TID
set the clipboard to resultList

For goTo type ⇧⌘G in Finder


regards

Stefan

Offline

 

#9 2014-03-19 09:55:41 pm

McUsrII
Member
Registered: 2012-11-21
Posts: 3046
Website

Re: getPath and goTo apps. Quick and easy location management

Hello.

I read about the goto shorcut above, I have missed the toolbar version of that. I think that a great leap forward for OS X apps is that a toolbar is mandatory for all regular windows, and that every toolbar must be able to execute an applet. smile

You'll have to open the property list after having saved the script below as an applet, and add an item "Application is Agent", which you must check off. (LSUIElment = 1 in XML).

Applescript:

-- [url]http://macscripter.net/viewtopic.php?pid=171787#p171787[/url]
(*
   Copyright © 2014 McUsr. All rights reserved.
*)

script goTo
   property onlyFromToolBar : false
   if not onlyFromToolBar then
       do shell script "open -a \"Finder\" "
       # In order to "disturbe" the window layout as little as possible.
       tell application "Finder"
           try
               set probe to id of its Finder window 1
               # we check if we have a window after all
           on error
               make new Finder window at desktop folder
               # if we didn't
           end try
           tell its Finder window 1
               tell application id "sevs" to tell application process "Finder" to keystroke "g" using {command down, shift down}
               # perform the keyboard shortcut
           end tell
       end tell
   else
       tell application id "sevs" to tell application process "Finder" to keystroke "g" using {command down, shift down}
       # perform only the keyboard shortcut
   end if
end script

on run
   run script goTo
end run

Edit

The real cool thing is that it remebers the last folder you went to. It is often so that, you bring up the goto folder dialog for a folder that is awkward to navigate to from Finder's  sidebar, and it is often probable that you want to revisit that folder again, so easy access is gold! smile

Edit++
I made it configurable to work from only the Toolbar, or from Toolbar, Spotlight bar (and stand-alone), as it then brings up the front finder window, and creates one if there weren't any.

Last edited by McUsrII (2014-03-20 12:32:27 am)


Filed under: goto

Offline

 

#10 2014-05-20 02:42:52 pm

threezerotwo
Member
Registered: 2014-05-20
Posts: 2

Re: getPath and goTo apps. Quick and easy location management

This is a really useful script. I've tried doing my own custom edit, but struggling a little.

Using this script…

Applescript:

activate application "SystemUIServer" -- works around a Finder selection bug
tell application "Finder"
activate
set theSelection to (get selection)
if theSelection is {} then display dialog "You must have something selected" buttons {"Cancel"} default button 1
set {button returned:pathMode, gave up:gaveUP} to display dialog "Choose HFS (:) or POSIX (/) format?" buttons {"Cancel", "HFS", "POSIX"} default button "POSIX" giving up after 2
end tell
set resultList to {}
repeat with oneFile in theSelection
set hfsPath to oneFile as text
if pathMode is "POSIX" or gaveUP then
set end of resultList to POSIX path of hfsPath
else
set end of resultList to hfsPath
end if
end repeat

set {TID, text item delimiters} to {text item delimiters, return}
set resultList to resultList as text
set text item delimiters to TID
set the clipboard to resultList

Ideally I'd like it to miss the choose HFS (:) or POSIX (/) format and auto copy a POSIX (/) format to the clipboard.

Once copied maybe message comes up to say 'copied' for a quick moment or you hit enter and the message removes itself.

Doing this would mean your hands never have to leave the keyboard.

Any pointers out there for editing it? All help and insight gratefully received.

Last edited by threezerotwo (2014-05-20 04:37:15 pm)

Offline

 

#11 2014-05-21 03:53:31 am

StefanK
Member
From:: St. Gallen, Switzerland
Registered: 2006-10-21
Posts: 11483
Website

Re: getPath and goTo apps. Quick and easy location management

here we go

Applescript:


activate application "SystemUIServer" -- works around a Finder selection bug
tell application "Finder"
   activate
   set theSelection to (get selection)
   if theSelection is {} then display dialog "You must have something selected" buttons {"Cancel"} default button 1
end tell
set resultList to {}
repeat with oneFile in theSelection
   set end of resultList to POSIX path of (oneFile as text)
end repeat

set {TID, text item delimiters} to {text item delimiters, return}
set resultList to resultList as text
set text item delimiters to TID
set the clipboard to resultList
tell application "Finder" to display dialog "Copied" buttons {"OK"} default button "OK" giving up after 1


regards

Stefan

Offline

 

#12 2014-05-21 06:34:45 am

threezerotwo
Member
Registered: 2014-05-20
Posts: 2

Re: getPath and goTo apps. Quick and easy location management

Works a treat, thank you Stefan.

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)