• 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
Re: Restoring the Finder Selection After Moving an Item or Items.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Restoring the Finder Selection After Moving an Item or Items.


  • Subject: Re: Restoring the Finder Selection After Moving an Item or Items.
  • From: Jim Underwood <email@hidden>
  • Date: Tue, 28 Feb 2017 18:55:08 +0000
  • Thread-topic: Restoring the Finder Selection After Moving an Item or Items.

Shane,

Perhaps the purpose/objective of your script is obvious to some, but not to me (and maybe not to other ASObjC neophytes).
It doesn't look like it changes any files or folders, but I can't be for sure, so I don't want to run it to see what happens.

It would be great, to help us learn, if you could clarify and add some comments.

Thanks.

Note to All:  The below script may not be exactly as Shane posted it.  MS Outlook seems to drop tabs/spaces sometimes in scripts.

Best Regards,

Jim Underwood
aka JMichaelTX


From: <applescript-users-bounces+jmichael=email@hidden> on behalf of Shane Stanley <email@hidden>
Date: Mon, Feb 27, 2017 at 1:13 AM
To: "ASUL (AppleScript)" <email@hidden>
Subject: Re: Restoring the Finder Selection After Moving an Item or Items.


OK, but what if I said it's a bad choice, because (a) it doesn't match the Finder's sort order, and (b) it doesn't match the Finder's hide/show extension preference? And that you can handle both and still be as fast, if not faster?

use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use scripting additions

tell application "Finder"
set winTarget to insertion location as alias
set finderSelectionList to selection as alias list


if finderSelectionList = {} then
beep
return
end if
set byName to name of sort column of list view options of Finder window 1 is name column
if byName then
set reverseOrder to sort direction of sort column of list view options of Finder window 1 is not normal
set itemName to name of (last item of finderSelectionList)
end if
end tell

set newItemName to ""
if byName then
-- get full name so Finder extension setting doesn't matter, nor use of slashes
set lastItemPath to POSIX path of (last item of finderSelectionList)
set lastItemPath to current application's NSString's stringWithString:lastItemPath
set itemFullName to lastItemPath's lastPathComponent()
-- list folder and sort the same way as Finder
set itemNames to (current application's NSFileManager's defaultManager()'s contentsOfDirectoryAtPath:(POSIX path of winTarget) |error|:(missing value))'s sortedArrayUsingSelector:"localizedStandardCompare:" -- sorted like Finder
if reverseOrder then set itemNames to itemNames's reverseObjectEnumerator()'s allObjects()
-- get index of the item
set theIndex to itemNames's indexOfObject:itemFullName
set theCount to itemNames's |count|()
-- there are more after it, so try to select the next one
if theIndex < theCount + 1 then set newItemName to (itemNames's objectAtIndex:(theIndex + 1)) as text
end if

tell application "Finder"
-- move finderSelectionList to destinationFolder
delay 0.05
try
tell front window to select item newItemName of winTarget
end try
end tell

Still not pretty, but hey...

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>, <latenightsw.com>

 _______________________________________________
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

  • Follow-Ups:
    • Re: Restoring the Finder Selection After Moving an Item or Items.
      • From: Shane Stanley <email@hidden>
References: 
 >Restoring the Finder Selection After Moving an Item or Items. (From: Christopher Stone <email@hidden>)
 >Re: Restoring the Finder Selection After Moving an Item or Items. (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Scripting Better Applescript support requests !
  • Next by Date: Resize and scale ID images in Photoshop
  • Previous by thread: Re: Restoring the Finder Selection After Moving an Item or Items.
  • Next by thread: Re: Restoring the Finder Selection After Moving an Item or Items.
  • Index(es):
    • Date
    • Thread