• 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: how to make a Finder Service using Automator and an Applescript
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: how to make a Finder Service using Automator and an Applescript


  • Subject: Re: how to make a Finder Service using Automator and an Applescript
  • From: Shane Stanley <email@hidden>
  • Date: Tue, 10 Oct 2017 14:33:20 +1100

On 10 Oct 2017, at 1:20 pm, Alastair Leith <email@hidden> wrote:
>
>  want to be able to select a file in Finder and have a Finder Service
> available to take the filename text and replace all the whitespace breaks
> between alphanumeric characters with hyphens.
>
> e.g. So "3.7 Enteric fermentation   emissions.pdf”  becomes
> “3.7-Enteric-fermentation-emissions.pdf"
>
> So when I generate a Dropbox link it becomes
> "https://www.dropbox.com/s/pe8enatl6g3nrbq/3.7-Enteric-fermentation-emissions.pdf?dl=0
>
> <https://www.dropbox.com/s/pe8enatl6g3nrbq/3.7-Enteric-fermentation-emissions.pdf?dl=0>”
>  rather than
> "https://www.dropbox.com/s/pe8enatl6g3nrbq/3.7 Enteric fermentation emissions copy.pdf?dl=0
>
> <https://www.dropbox.com/s/pe8enatl6g3nrbq/3.7 Enteric fermentation emissions copy.pdf?dl=0>"
>
> In grep i’d simply search for all “\s+” and replace with “-“. Do I need to
> write an Applescript (or Grep shell script) and then run it from automator?
>
> I know it’s a remedial question but any help to get me started will be
> gratefully received.

Is there some reason it has to be a service? It's easy enough to have a script
that runs from the Scripts menu, or better still use FastScripts so you can
assign it a shortcut. Something like this:

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

tell application "Finder"
        set theItems to selection as alias list
end tell

set fileManager to current application's NSFileManager's defaultManager()
repeat with anItem in theItems
        set thePath to POSIX path of anItem
        set thePath to (current application's NSString's
stringWithString:thePath)
        set newName to (thePath's lastPathComponent()'s
stringByRemovingPercentEncoding()'s stringByReplacingOccurrencesOfString:space
withString:"-")
        set newPath to (thePath's stringByDeletingLastPathComponent()'s
stringByAppendingPathComponent:newName)
        (fileManager's moveItemAtPath:thePath toPath:newPath |error|:(missing
value))
end repeat

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

References: 
 >how to make a Finder Service using Automator and an Applescript (From: Alastair Leith <email@hidden>)

  • Prev by Date: how to make a Finder Service using Automator and an Applescript
  • Next by Date: Re: how to make a Finder Service using Automator and an Applescript
  • Previous by thread: how to make a Finder Service using Automator and an Applescript
  • Next by thread: Re: how to make a Finder Service using Automator and an Applescript
  • Index(es):
    • Date
    • Thread