Folder action to find and replace text and change line feeds

I want to use a folder action to find and replace text and change Mac carriage returns to DOS line feeds inside text files.
The text to be replaced is: "/Users/wim/Music/iTunes/iTunes Music/Music" (without the quotes)
This text has to be removed (i.e. replaced by an empty string)
The text occurs many times within each file.
The files are playlists exported from iTunes in the M3U format (which are text files). They contain Mac carriage returns. These need to be changed to DOS line feeds.
I have found the following two perl commands to achieve this:
To find and replace text: perl -pi -w -e 's/THIS/THAT/g;' *.txt
To change carriage returns to line feeds: perl -i -pe 's/\015/\015\012/g' mac-file
I know that it's possible to make a folder action with Automator that executes a shell script.
What I want to do is drop the exported playlists in M3U format in a folder so that the folder action will remove the right text and change the carriage returns.
My questions are:
Is it possible to make a folder action that executes command line commands instead of shell scripts?
What is the correct syntax for the two commands when used in a folder action shell script? Especially, how do I escape the slashes (/) in the string to be removed?
Thanks for your help

Ok, I've include an applescript to run a shell command. The applesript command quoted form makes a string that will end up as a single string on the bash command line.  Depending on what you want to do, you may need multiple string on the bash command lines.  I've included some information on folder actions.
It is easier to diagnose problems with debug information. I suggest adding log statements to your script to see what is going on.  Here is an example.
    Author: rccharles
    For testing, run in the Script Editor.
      1) Click on the Event Log tab to see the output from the log statement
      2) Click on Run
    For running shell commands see:
    http://developer.apple.com/mac/library/technotes/tn2002/tn2065.html
on run
    -- Write a message into the event log.
    log "  --- Starting on " & ((current date) as string) & " --- "
    --  debug lines
    set desktopPath to (path to desktop) as string
    log "desktopPath = " & desktopPath
    set unixDesktopPath to POSIX path of desktopPath
    log "unixDesktopPath = " & unixDesktopPath
    set quotedUnixDesktopPath to quoted form of unixDesktopPath
    log "quoted form is " & quotedUnixDesktopPath
    try
        set fromUnix to do shell script "ls -l  " & quotedUnixDesktopPath
        display dialog "ls -l of " & quotedUnixDesktopPath & return & fromUnix
    on error errMsg
        log "ls -l error..." & errMsg
    end try
end run
How to set up a folder action.
1) right click on folder. click on Enable folder actions
2) Place script in
/Library/Scripts/Folder Actions Scripts
3) right click on folder. click on attach folder action
pick your script.
Create a new folder on the desktop & try.
You can put multiple folder actions on a folder. There are other ways of doing this.
Here is my test script:
on adding folder items to this_folder after receiving dropped_items
    repeat with dropped_item_ref in dropped_items
       display dialog "dropped files is " & dropped_item_ref & " on folder " & this_folder
    end repeat
end adding folder items to
How to  make the text into an AppleScript program.
Start the AppleScript Editor
/Applications/AppleScript/Script Editor.app
In Snow Leopard it's at: /Applications/Utilities/AppleScript Editor
Copy the script text to the Applescript editor.
Note: The ¬ is typed as option+return.  ption+return is the Applescript line continuation characters.
You may need to retype these characters.
Save the text to a file as an script and do not check any of the boxes below.

Similar Messages

  • Find and Replace text and change font help needed.

    I am completely new to Scripting and I'm sure this is quite simple but I do not know where to start.
    I have a FM template that is populated with "raw" text from a database.
    Within the text are several characters (+, @, *, $, # and %).
    I need to replace these characters with symbols from a different font e.g.:
    Each instance of:
    "+" to be replaced with Wingdings 2 font - Lowercase t
    "@" to be replaced with Wingdings 2 font - Lowercase u
    "*"  to be replaced with Wingdings font - Uppercase E   etc.
    I would like to automate the process and believe a script would enable me to do this.
    I have tried looking on the forum, but can not find anything suitable to help me (or I'm looking in the wrong place).
    Any help would be greatly appreciated.
    Cheers
    Kev

    not really
    important is the Illustrator Text Object-model, which is not very easy to understand.
    And the Core JS String and regExp Objekts.
    Have a look at this:
    http://www.ogebab.de/home/skripte/text/replace
    The dialog is poor (because of compatibility) and it works simply on TextFrames.contents, i don't know if this is good i all cases.
    But i use it not very often so i don't want to rewrite it.
    Maybe it is a starting-point for you.
    But maybe it is more then you need.
    try this:
    //select a text
    var text = app.activeDocument.selection[0];
    var string = text.contents;
    string = string.replace(/ /g,"  ");
    text.contents= string;
    / /g is a regular expression
    .replace() is a method of the String Object
    both explained at
    https://developer.mozilla.org/en/JavaScript/Reference

  • Use VBA and Excel to open Dreamweaver HTML (CS5), find and replace text, save and close

    I wish to use VBA and Excel to programmatically open numbered Dreamweaver HTML (CS5) and find and replace text in the code view of these files, save and close them.
    I have  5000 associations between Find: x0001 and Replace: y0001 in an Excel sheet.
    I have the VBA written but do not know how to open, close and save the code view of the ####.html files. Please ... and thank you...
    [email protected]

    This is actually the code view of file ####.html that I wish to find and replace programmatically where #### is a four digit number cataloguing each painting.... In 1995 I thought this was clever... maybe not so clever now :>)) Thank you for whatever you can do Rob!
    !####.jpg!
    h2. "Name####"
    Oils on acrylic foundation commercial canvas - . xx X xx (inches) Started
    Back of the Painting In Progress </p> </body> </html>
    Warmest regards,
    Phil the Forecaster, http://philtheforecaster.blogspot.ca/ and http://phils-market.blogspot.ca/

  • Find and Replace text string in HTML

    Opps... I hope this forum is not just for Outlook. My Html files reside on my hard-drive. I am looking for VBA code to open specified file names ####File.html and then find and replace text strings within the html for example "####Name" replaced
    with "YYYYY"
    I drive the "####File.html" names and the find and replace text strings from an Excel sheet. I am an artist and this Sub would give me time to paint instead of find and replace text. Thank you!
    [email protected]

    Hello Phil,
    The current forum is for developers and Outlook related programming questions. That's why I'd suggest hiring anybody for developing the code for you. You may find freelancers, for example. Try googling for any freelance-related web sites and asking such
    questions there.
    If you decide to develop an Outlook macro on your own, the
    Getting Started with VBA in Outlook 2010 article is a good place to start from.

  • In Pages, how to search and replace text involving invisible characters?

    In Pages documents, how to search and replace text involving invisible characters, colors and font sizes—a task which is so easy in Mircosoft Word?

    I read that an older version of Pages allowed users to enter special characters in the search/replace fields, but this did not work for me.
    Here: http://www.macworld.com/article/1156533/pagesspecialcharacters.html
    I still am looking for a way to do this.

  • Find and replace m2 and m3 to subscripts

    Now I change m2 and m3 to what on the clipboard.  But that doesn't work when I have m2 and m3 in different colors and different fonts tru the lay-outs. 
    How can I find and replace m2 and m3 to m subscript 2 and m subscript 3?
    Only m2  not 2 alone.
    Many thanks

    Your "Only m2 not 2 alone" seems to contradict what you wrote earlier, but I guess that what you want is to style 2 and 3 only when they are preceded by m. If that's the case, do this in the grep tab of the Find/Change dialog:
    Find what: (?<=m)[23]
    Change to: <leave empty>
    Change format: select subscript.
    (?<=. . .) is a so-called lookbehind, [. . .] a character class. (?<=m) means 'preceded by' and [23] stands for '2 or 3'.
    Peter

  • Purchased Acrobat XI Pro - was able to edit text and add text and now does not allow me to do anything -

    was able to edit text and add text and now does not allow me to do anything - Except purchase the software again.Can't find an answer to this anywhere.

    Use Adobe Acrobat, not Adobe Reader.

  • When I use Preview,Photo Mechanic and Pages, all JPEG or RAW images appear corrupted. I thought my hard drive was failing and replaced it and migrated everything over but the problem still exists. Any idea what is going on?

    When I use Preview,Photo Mechanic and Pages, all JPEG or RAW images appear corrupted.
    I thought my hard drive was failing and replaced it and migrated everything over but the problem still exists.
    It felt as if maybe a virus was at work but I ran Sophos and found nothing.
    I store images on my Drobo Raid system but when I work from my Macbook Pro I have no issues, just on the tower.
    Any idea what is going on?

    First of all, why did you say yes to Nero Back up before researching what it does with files already on the HDD? When I install Nero, the Back Up is the first thing I disable, it is a nagging pain, there are much better backup programs available. There are several file recovery programs out there to recover deleted files, that is, if that is what happened. Also, if you haven't overwritten the files, so you should be able to find them.

  • Copy and paste text and graphics between Flash and Illustrator

    When copying text in Illustrator and pasting them to Flash, some text would become drawing objects and some remain text. A drawing object is not editable. If I import the AI file, then text remains text but the placement of graphics can be a little bit off sometimes.
    It's just not possible to copy-and-paste text and graphics from Flash to Illustrator.
    Is it just me? If not, when will Adobe have better integration between the 2?
    Thanks,

    Even though you can change your InDesign preferences for Clipboard Handling to allow formatted information to be pasted into InDesign from other programs, unfortunately Illustrator still won't allow you paste in text with formatting. This is due to how Illustrator and InDesign handle text differently. Even if you copy the text from Illustrator and paste it into a program like Word, which has a lot of different ways to handle formatted text, Illustrator just treats text differently than other Adobe applications.

  • TS3406 I have a connection in the top left hand corner and can access the internet with and without internet on my iphone 5c but I can't receive and create texts and calls, someone please help have tried everything!

    I have a connection in the top left hand corner and can access the internet with and without internet on my iphone 5c but I can't receive and create texts and calls, someone please help have tried everything!

    YOu will need to contact your cell phone provider to resolve those issue, those are carrier features.

  • HT4993 Why iPhone 4S keeps sending double and triple texts, and random words I never typed. Any ideas?

    Why iPhone 4S keeps sending double and triple texts, and random words I never typed. Any ideas?

    Jailbroken?
    is this happening to SMS and iMessages?

  • My phone will on send and receive text and emails, I can't make or receive calls

    My phone will only send and receive text and emails, I can't make or receive calls. Please help

    Have you tried rebooting the phone?  Also maybe removing and reinstalling the sim card?  Make sure your not in airplane mode or check under settings -- general --cellular and see whats turned on or off.

  • How to find and replace text in Excel with Automator

    I am new to Automator. And I would like some help how I can create a service that will allow me to find and replace certain text in Excel. I noticed that there is an action to do this for Word documents, but not for Excel document.
    Any suggestions how I can do this?
    Thanks so much for your help.

    Easiest way to do it is the following:
    - Open the PDF file in Acrobat.
    - Go to Tools - Forms - More Form Options - Export Data.
    - Save the form data as an XML file somewhere on your system.
    - Open XML the file in a plain-text editor (I recommend Notepad++).
    - Let's say you want to replace all the years in the dates from "2013" to "2014". Do a global Search&Replace of "2013-" to "2014-" (I added the dash just to make sure that only date fields are edited).
    - Save the XML file (maybe under a new name).
    - Go back to the PDF file, and now go to Tools - Forms - More Form Options - Import Data.
    - Select the edited XML file and import it.
    - Done!

  • How do I find and replace text in PHP files?

    How can I in CS3 make sitewide changes to the text in PHP pages without changing variable names etc that have the same name?
    For example if I have an installation of a PHP forum and I want to change every instance of the word 'forum' to 'message board'...
    If I used the 'inside tag' search with " as the tag, then if "" contained a variable called 'forum' it would also be changed and therefore corrupt the code....
    Is there a simple way around this?
    Thanks!
    I'm using CS3 on Windows Vista.

    It looks like you're trying to find and replace source code, so you may be able to look at the various places that are looked at when finding and uncheck the ones that don't apply.
    But, if it's all source code then that won't help.  One thing that may work is to expand the search option - for example if the work "forum" that you're wanting to change it preceded by another word, or character or something that sets it apart, then do you find on that. You can expand that search phrase as far out in either direction that you need to to make it different, if of course that is practical in your situation.
    The only other way I can think of is to somehow create an exception rule, but I'm not sure if that's possible or how to do it.

  • [Forum FAQ] How to find and replace text strings in the shapes in Excel using Windows PowerShell

    Windows PowerShell is a powerful command tool and we can use it for management and operations. In this article we introduce the detailed steps to use Windows PowerShell to find and replace test string in the
    shapes in Excel Object.
    Since the Excel.Application
    is available for representing the entire Microsoft Excel application, we can invoke the relevant Properties and Methods to help us to
    interact with Excel document.
    The figure below is an excel file:
    Figure 1.
    You can use the PowerShell script below to list the text in the shapes and replace the text string to “text”:
    $text = “text1”,”text2”,”text3”,”text3”
    $Excel 
    = New-Object -ComObject Excel.Application
    $Excel.visible = $true
    $Workbook 
    = $Excel.workbooks.open("d:\shape.xlsx")      
    #Open the excel file
    $Worksheet 
    = $Workbook.Worksheets.Item("shapes")       
    #Open the worksheet named "shapes"
    $shape = $Worksheet.Shapes      
    # Get all the shapes
    $i=0      
    # This number is used to replace the text in sequence as the variable “$text”
    Foreach ($sh in $shape){
    $sh.TextFrame.Characters().text  
    # Get the textbox in the shape
    $sh.TextFrame.Characters().text = 
    $text[$i++]       
    #Change the value of the textbox in the shape one by one
    $WorkBook.Save()              
    #Save workbook in excel
    $WorkBook.Close()             
    #Close workbook in excel
    [void]$excel.quit()           
    #Quit Excel
    Before invoking the methods and properties, we can use the cmdlet “Get-Member” to list the available methods.
    Besides, we can also find the documents about these methods and properties in MSDN:
    Workbook.Worksheets Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff835542(v=office.15).aspx
    Worksheet.Shapes Property:
    http://msdn.microsoft.com/en-us/library/office/ff821817(v=office.15).aspx
    Shape.TextFrame Property:
    http://msdn.microsoft.com/en-us/library/office/ff839162(v=office.15).aspx
    TextFrame.Characters Method (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff195027(v=office.15).aspx
    Characters.Text Property (Excel):
    http://msdn.microsoft.com/en-us/library/office/ff838596(v=office.15).aspx
    After running the script above, we can see the changes in the figure below:
    Figure 2.
    Please click to vote if the post helps you. This can be beneficial to other community members reading the thread.

    Thank you for the information, but does this thread really need to be stuck to the top of the forum?
    If there must be a sticky, I'd rather see a link to a page on the wiki that has links to all of these ForumFAQ posts.
    EDIT: I see this is no longer stuck to the top of the forum, thank you.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

Maybe you are looking for