Change selected file in automator using applescript ???

So I'm getting better at using Automator to create useful Services but still a bit of a newbie with doing powerful things with AppleScript... and I think this task requires some applescripting. Here's what I want to do:
1. Based on a selected text file I want to run a pre-existing script that converts this file into an HTML file. This new file has the same name as the text file but has the .html extension rather than the .txt extension. (This step is easy enough with Automator and it works just fine already.)
2. BUT NOW, I want to take that resulting HTML file and run another pre-existing script that converts the HTML file into an RTF file. The problem is that I basically want to change the selection from selectedfile.TXT to selectedfile.HTML so that I can proceed to this next step...
3. AND THEN, I want to launch an app with this resulting RTF file. Again, I need to change the selection to selectedfile.RTF.
Right now this requires me to run three different automator services, and changing the selected file between each step... But I'm sure there's an easy applescript way (or other way) to do this using just one service -- probably involves some filename parsing and some magic to change the selection??? -- or something like that...
Could anyone point me in the right direction???
Thank you thank you thank you!
~zyyyy

Have you considered using a bash script? You can even write the script in an Automator Service.
Open Automator and select Service from the main screen. Set the ‘Service Receives Selected’ pop-up menu to Files or Folders, and set the ‘in’ pop-up to Finder. Drag Run Shell Script from the Utilities section of the actions library into the workflow area. Set Pass Input to As Arguments. Replace the sample code in the input area with this:
for f in "$@"
do
file_ext="${f##*.}"
if [ $file_ext = "txt" -o $file_ext = "TXT" ] ; then
/usr/bin/textutil -convert html "$f"
/usr/bin/textutil -convert rtf "${f/$file_ext/html}"
/usr/bin/open -a /Applications/TextEdit.app "${f/$file_ext/rtf}"
fi
done

Similar Messages

  • How can I change the file download time using Adobe Send? Adobe SendNow had a lot more options.

    How can I change the file download time using Adobe Send? Adobe SendNow had a lot more options.I don't see nay with Adobe Send.

    There isn't a feature in Adobe Send for setting and end-date for a file's availability. At any time, you can Unshare the file, however.

  • Getting Selected Project in Aperture using AppleScript

    Is it possible to get a reference to the currently selected project in Aperture using AppleScript? In other words, is it possible to get the project containing the currently selected image (which I can get by using "selection")? If possible, how can I do it?

    GIve this a try:
    tell application "Aperture"
    set x to selection
    set x to item 1 of x
    tell library 1
    get value of other tag "MasterLocation" of x
    end tell
    end tell
    One thing that helps to answer similar questions is to ask for properties of objects. That can reveal more about an object. Another way to help answer these kinds of questions is to ask for available tags in Exif, IPTC, and "other tags" of a particular image version. That will tell you all the available tags that have values assigned for a particular image version. You can then explore those tags to see if what you are looking for is available.
    Hope that helps.
    Message was edited by: lenny

  • Change selected file to a file with same name but different extension.

    So I'm getting better at using Automator to create useful Services but still a bit of a newbie with doing powerful things with AppleScript... and I think this task requires some applescripting. Here's what I want to do:
    1. Based on a selected text file I want to run a pre-existing script that converts this file into an HTML file. This new file has the same name as the text file but has the .html extension rather than the .txt extension. (This step is easy enough and it works just fine already.)
    2. BUT NOW, I want to take that resulting HTML file and run another pre-existing script that converts the HTML file into an RTF file. The problem is that I basically want to change the selection from selectedfile.TXT to selectedfile.HTML so that I can proceed to this next step...
    3. AND THEN, I want to launch an app with this resulting RTF file. Again, I need to change the selection to selectedfile.RTF.
    Right now this requires me to run three different services, and changing the selected file between each step... But I'm sure there's an easy applescript way (or other way) to do this using just one service -- probably involves some filename parsing and some magic to change the selection??? -- or something like that...
    Could anyone point me in the right direction???
    Thank you thank you thank you!
    ~zyyyy

    You can chain your scripts together - depending on the complexity of your pre-existing scripts, you could do this with either AppleScript or Automator. The workflow would just take the selected text file (from step 1), convert to both HTML (2) and RTF (3), then launch your application with the resulting RTF - no need to change any selection.
    By the way, this is the Tiger Automator forum - Snow Leopard's Automator is quite a bit different, so you will probably have better luck posting in the Snow Leopard forum.

  • Pse 7 changes the file extensions, by using a -1 up to 6 times on a photo, how to stop this problem.

    I cannot keep up with my photos, they somehow change the file extension by adding
    a -1 over and over, how can I stop this process
    to keep a single file extension?

    I checked out the backup/sync, it is not turned on after checking.   Also I do not have a second computer as a backup, I use an Esata drive of 1 TB.
    I have a photo called Rose.jpg, later I try to open the file and it tell be its lost.  I try to reconnect, no luck, then I manually try to find the file and its called Rose-1.jpg or up to Rose-1-1-1-1-1-1.jpg or Rose-1-1-1-1-1-1_edited.jpg.  I do not understand what is taking place in my computer with my photos.   I have about 17,000 photos and I am having a real problem.
    Any help would be appreciated.  sghmotorhome

  • Problem with changing URL within Safari window using AppleScript

    hey everyone,
    I'm currently trying to write a script that will open Safari, then change the URL within that same Safari window, and then quit Safari. However, I'm currently having a few problems:
    1) Sometimes two Safari windows will open. One will go to what I'm guessing is the default homepage, and the other will go to Google.
    2) I cannot figure out or find a way to change the URL within that window using AppleScript.
    Does anyone have any ideas as to how to go about doing these things? I'm pretty new to AppleScript, so if what code I already have is poorly written, please let me know. Thanks!
    --Open Finder and tell it to open Safari
    tell application "Finder"
    set site1 to "http://www.google.com"
    set site2 to "http://www.yahoo.com"
    launch application "Safari"
    tell process "Safari"
    open location site1
    delay 10
    open location site2
    delay 10
    end tell
    end tell
    --After waiting the allotted time, tell Safari to quit.
    tell application "Safari"
    quit
    end tell
    --Jonathan

    Welcome to Apple Discussions!
    You don't need to tell the Finder to open Safari - you can address it directly.
    This should be self-explanatory, but do ask away if you have any questions.
    (If there's only one window open - as per your description - it will take the first URL. Otherwise - if there are zero or many windows open - a new window will be opened for each URL.)
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFDDFF;
    overflow: auto;">
    tell application "Safari"
    activate
    if (count of windows) is not 1 then
    set theFirstWindow to make new document at end of documents
    else
    set theFirstWindow to document of front window
    end if
    set URL of theFirstWindow to "http://www.yahoo.com"
    set theSecondWindow to make new document at end of documents
    set URL of theSecondWindow to "http://www.google.com"
    end tell </pre>

  • Numbers: Save file as xls using AppleScript

    Hi all,
    I need to remove all the external links from an Excel file. Tried to do this first using Automator and the Excel actions, but every time Excel opens one of the files it displays an error message that it's missing the external files and the Automator sequence is pauzed. Now I found out that if I open the Excel file with the Numbers app and save it again in the same file format (xls), the links are broken.
    Now my question is how I can open the Excel files using Numbers and save them again as xls files. Since there are no Automator actions for Numbers, I'd like to accomplish this by using an AppleScript, which I'm very new to. Somebody help?
    Thanks in advance

    Some nice scripts for saving iWork files to Office formats were listed here.
    I think the problem comes in with opening the Excel file with Numbers in a script. I believe this often brings up a Document Warnings window that requires user input, and I haven't seen any good way to deal with that in a script.

  • Move Files with Automator or Applescript

    I am a newbie to Applescript and Automator and I'm afraid I'm in way over my head.  I need to move a bunch of files in a single folder to several different folders based on the file name.  Is this possible?
    Specifically, several files with names "word1 word2 word3 word4.pdf" are placed in a folder then they will be moved to different folders based on word4.
    Ideally, if possible, I would then have to append to things to the file name.  At the beginning of the file name a three digit code based on word4 (or the folder) and then at the end of the file name a date stamp.  The date stamp should be in the form of four digit year, two digit month, and two digit day with no spaces in between.  Where, year is the year of current month -1, month is current month -1, and day is the last day of current month -1.
    Is there any way to do this?
    Thanks!

    your description is still underspecified, so this script probably won't work out-of-the-box, but it will get you close.
    on adding folder items to this_folder after receiving these_items
              repeat with thisItem in these_items
                        set fileName to nameWithoutExtension(thisItem)
                        set accountName to last word of fileName
                        set accountCode to codeForPerson(accountName)
                        set dateSlug to dateString()
                        set newFileName to accountCode & " " & fileName & " " & dateSlug & ".pdf"
                        tell application "System Events"
      -- you haven't specified actual file path, so I'm assuming your destination folder is inside your folder action folder
                                  set destinationFolder to folder "Statements" of folder accountName of this_folder
                                  set movedFile to move f to destinationFolder
                                  set name of movedFile to newFileName
                        end tell
              end repeat
    end adding folder items to
    on nameWithoutExtension(p)
              tell application "System Events"
                        set {n, x} to {name, name extension} of p
              end tell
              return (text 1 thru -((length of x) + 1) of n)
    end nameWithoutExtension
    on dateString()
              set d to current date
              set day of d to 1
              set {y, m, d} to {year, month, day} of (d - 1 * days)
              return (y as string) & zeroPadDigit(month * 1, 2) & zeroPadDigit(day, 2)
    end dateString
    on zeroPadDigit(d, p)
              return text -p through -1 of ("000" & d)
    end zeroPadDigit
    on codeForPerson(n)
              if n = "Smith" then
                        return "001"
              else if n = "Jones" then
                        return "002"
              else if n = "Doe" then
      -- you haven't specified how these numbers are determined
              else
      -- return default value for unspecified accounts
              end if
    end codeForPerson

  • How do I save an excel file as XML using applescript.

    I set display alerts to false, but excel will not save.  I get error -1708.
    My code looks as such:
    set theFile to "Macintosh HD:Users:Dustin:Documents:products.xlsx"
    tell application "Microsoft Excel"
      activate
      open theFile
              set display alerts to false
              tell active sheet
      save as filename "products.xml" file format XML spreadsheet file format
              end tell
      close active workbook without saving
              set display alerts to true
    end tell
    end
    If I remove the code to set the display alerts, excel pops up an display alert to continue or cancel the save.
    I'll take anything at this point....

    Are you sure you want to do a "SAVEAS" to create the PDF?  What version of MS Office are you using?
    One of the best ways to figure out how to do something with ActiveX in Excel is to first do it in Excel by recording a Macro.  See what code Excel generates, then try to model that in LabVIEW.
    I don't see .pdf as an option you can save Excel as a filetype to (Excel 2007).  But when I go to the Excel 2007 button, Save As, then PDF or XPS while recording a macro, I get this code.
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
    "C:\Documents and Settings\CurrentUser\Desktop\FILENAME.pdf", Quality:= _
    xlQualityStandard, IncludeDocProperties:=True, IgnorePrintAreas:=False, _
    OpenAfterPublish:=True
       This shows me you should be usingthe ExportAsFixedFormat method on the worksheet as opposed to trying to use the SaveAs method on the workbook.  (But the workbook object as that same method as well.)

  • Unable to change .jsp file at runtime using weblogic 8.1 server

    Hello all,
    I'm running weblogic 8.1 and the development environment is workshop.
    I have several .jsp files in the application.
    when the server is running and I try to change the .jsp file and access it throw the browser, I'm getting compilation errors and when I copy the original file again everything is OK.
    I'm gessing the problem occurs due to the date of the new .jsp file(if I compile the .jsp file it creates a new servlet with newer date then the file generate when compiling the application before running the server).
    Your advice will be welcome.

    Hi Robert,
    Take a look at the SAP Note "[1553921 - Is there a utility that would help in writing database logon code?"|http://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/oss_notes_boj/sdn_oss_boj_bi/sap(bD1lbiZjPTAwMQ==)/bc/bsp/spn/scn_bosap/notes%7B6163636573733d36393736354636443646363436353344333933393338323636393736354637333631373036453646373436353733354636453735364436323635373233443330333033303331333533353333333933323331%7D.do]
    The utility provided in above SAp Note will generate the logon code for your existing report, update the logon information of the target database in the code.
    Also search for the sample application 'change database at runtime' in top right corner search box.
    Hope it helps,
    Thanks,
    Bhushan.

  • Selecting unused color swatches using applescript?

    I cannot seem to remove unused colors from my swatches palette... got any suggestions?..
    here's a few sample of what i've done so far...
        --set ColorWell to every page item of group item 1 of layer "Image Layer" of current document as list
        --set ColorList to {} as list
        --set ColorList to name of every swatch of selection
        set ColorList to name of every swatch of imposition as list
        set ColorList2 to name of every swatch of current layer as list
        (*repeat with EachItem in ColorWell
            set ColorList to ColorList & (name of fill color of EachItem as string) as list
        end repeat*)
        --log ColorWell
        --log ColorList
        (*repeat with EachColor in ColorList
            if not (exists name of swatch EachColor) then
                    delete swatch EachColor of current document
            end if
        end repeat*)
        (*repeat with EachColor in ColorList
            --if swatch EachColor exists then
            if page items of ImageLayer contains {fill color:EachColor} then
                return
            else
                delete swatch EachColor of current document
            end if
            delay 1
        end repeat*)
        (*set PossibleColor to 1
        repeat (count swatches of current document) times
            if swatch PossibleColor of ImageLayer exists then
                return
            else
                delete swatch PossibleColor of current document
            end if
            set PossibleColor to PossibleColor + 1
        end repeat*)
    thanks...

    Try this:
    tell application "Adobe Illustrator"
    set myswatches to every swatch of document 1
    repeat with myswatchnum from (count of items in myswatches) to 1 by -1
    set myswatch to item myswatchnum of myswatches
    try
    set myfilledpaths to (path items of document 1 whose fill color = (color of myswatch))
    if myfilledpaths is {} then
    set mystrokedpaths to (path items of document 1 whose stroke color = (color of myswatch))
    if mystrokedpaths is {} then
    try
    delete swatch myswatchnum of document 1
    end try
    end if
    end if
    end try
    end repeat
    end tell

  • Change config file properties programatically

    hi, all i have created one config file and from that file i am readindg data. Now when i click on this file it shows that this file is in read only format. Now in this same config file i want to write the data but when i try to write data by using write key function it gives me some error just like please check the permission of the file.
    For this config file i canot change its permission to archive permenantly. So Is there any way to change the file permission programatically from read only archieve and again from archieve to read only.

    You can change the file permissions programmatically using LabVIEW.  This allows you to temporarily change the permission and modify the file before restoring the permissions to their original settings.
    The Set Permission is found within the Advanced File Functions of the File I/O section of the Functions Palette.
    The information below is from the Context Help.
    R
    Message Edited by JoeLabView on 09-16-2008 08:07 AM
    Attachments:
    filePermission.PNG ‏33 KB

  • Use applescript w/automator to change files permissions

    Hi, I need to change permission to several files to Read and Write to the Owner, Staff and everyone. I do this everyday, that's why I need someway to automate this action. I don't know about scripting but I do know (more or less) how to create a service in Automator. I am looking to create a service in automator which runs an applescript that changes this file's permissions. I need this to be applied to all sub folders and subfiles. Any clue what the applescript should say? Thnx

    Perfect! It worked perfectly even though I didn't understood the difference between the first shell script and the other. I've tried both, and they both did the same thing: They changed the Owner, the Staff and Everyone to Read and write.
    For my tests, this is what I did (for the sake of all the non geeky guys like me who needs this):
    I opened Automator and choose to make a Service, and set it to Files and Folders in Finder.
    Then I added the finder action "Get selected finder items".
    Then added "Run shell script" and did what you told me, and that's it!
    Thanx for your time

  • Automator or Applescript using png files with alpha channel

    I have hundred of png files with alpha channel.
    I want to suppress alpha channel.
    How can i do it using Automator or Applescript ?
    Thank you very much.

    You can use the free command line image processing tool ImageMagick in your Applescripts or Automator workflows, as well as from a Terminal shell.
    You can download ImageMagick from http://www.imagemagick.org, but Cactuslab has simplified installation by putting together an installer package. It’s available at  http://cactuslab.com/imagemagick/. Download the package and double-click on it. Follow the instructions to install. It will install ImageMagick into /opt/ImageMagick and add it to your $PATH by creating a file in /etc/paths.d/. Restart your computer for the changes to take effect.
    The two ImageMagick commands we’re concerned with are “convert” and “mogrify”. Convert is more efficient for multiple and piped operations on the same image file, and mogrify is more efficient for batch processing. Generally speaking, convert will output a file separate from the input file. Unless a path is specified, mogrify will overwrite the input file with the output file. An important distinction.
    You can perform various operations on the alpha channel using arguments after either the convert or mogrify command. Two of the available arguments are:
    -alpha off - Disables the image's transparency channel. Does not delete or change the existing data, just turns off the use of that data.
    -alpha remove - Composite the image over the background color.
    Also of use are the -flatten and -background options:
    -flatten - overlay all the image layers into a final image and may be used to underlay an opaque color to remove transparency from an image.
    -background - sets the background color.
    Start off using the convert command with a single image to see the effect and adjust to your liking. Once you’ve achieved the desired outcome, then use the mogrify command to batch process the chosen images.
    Before getting into how to use Automator or Applescript in your workflow, use Terminal and the command line to see the effect on a single image. Copy one image to your ~/Desktop. In Terminal change the directory to ~/Desktop by typing the following command and pressing the Enter key:
    cd ~/Desktop
    Then choose the option you are looking for, -alpha remove for instance, type the following command and press the Enter key:
    convert input-photo.png -alpha remove output-photo.png
    You can check the alpha channel (transparency) and background in the Preview app, go View > Show Image Background from the menu bar.
    Once you’re ready to batch proces, place all the photos you want to convert with the same command into one folder. Copy the folder to your ~/Desktop. Let’s assume you’ve labeled the folder “InPhotos”. It’s prudent to manipulate copies in case something goes amiss. In that event you can copy the folder with the originals again and start over. Create a new empty folder on your ~/Desktop and call it “OutPhotos”. Let’s also assume your home directory is called “Me”. The following command will process the photos from the InPhotos folder and put them in the OutPhotos folder:
    mogrify -alpha remove -path /Users/me/Desktop/OutPhotos/ /Users/me/Desktop/InPhotos/*png
    According to Apple Technical Note TN2065:
    "when you use just a command name instead of a complete path, the shell uses a list of directories (known as your PATH) to try and find the complete path to the command. For security and portability reasons, do shell script ignores the configuration files that an interactive shell would read"
    So, you need to use the full path to to ImageMagick commands, unlike in the shell where you can just use the command name.
    To batch process using Automator, use the “Run Shell Script” action (note: retain the single space at the beginning of the last line):
    /opt/ImageMagick/bin/mogrify \
    -alpha remove \
    -path /Users/Me/Desktop/OutPhotos/ \
    /Users/Me/Desktop/InPhotos/*png
    To batch process using Script Editor (Applescript), use the “do shell script” command:
    do shell script "/opt/ImageMagick/bin/mogrify -alpha remove -path /Users/pd/Desktop/OutPhotos/ /Users/pd/Desktop/InPhotos/*png"
    Further info on ImageMagick:
    http://www.imagemagick.org/script/command-line-options.php#alpha
    http://www.imagemagick.org/Usage/masking/#remove
    http://www.imagemagick.org/index.php
    http://www.imagemagick.org/script/command-line-tools.php
    http://www.imagemagick.org/script/command-line-options.php
    Examples:
    The original PNG image:
    -alpha off:
    -alpha remove:
    -background black -flatten:
    -background blue -flatten:
    -channel alpha -evaluate Divide 2:
    -channel alpha -evaluate Divide 2 -background black -flatten:

  • Using Applescript and Automator to manage files and folders

    Hi all.
    I need to make a simple action via applescript and-or automator to take the file it's been applied to (via the services) create a folder around it with the same name as the file.
    So far, I've searched the web, found some solutions but none are really working.
    Here's the script I found :
    set myFolder to findFolder()
    tell application "Finder" to set myFiles to files of myFolder as alias list
    repeat with aFile in myFiles
      set bName to my baseName(aFile)
      tell application "Finder"
      set folderExists to exists folder bName of myFolder
      if not folderExists then make new folder at myFolder with properties {name:bName}
      move aFile to folder bName of myFolder
      end tell
    end repeat
    ---------------- HANDLERS ----------------
    on baseName(myFile)
      tell application "System Events" to set {fileName, fileExt} to {name, name extension} of myFile
      return text 1 thru ((get offset of "." & fileExt in fileName) - 1) of fileName
    end baseName
    on findFolder()
      activate application "SystemUIServer"
      -- Bug pointed out by Lauri Ranta http://www.openradar.me/9406282
      tell application "Finder"
      activate
      set mySelection to (get selection)
      if mySelection ≠ {} then
      set mySelection to first item of (get selection)
      if mySelection's class = folder then
      set currentFolder to mySelection
      else if mySelection's class = document file then
      set currentFolder to parent of mySelection
      else if mySelection's class = alias file then
      set currentFolder to original item of mySelection
      end if
      else
      set currentFolder to target of front Finder window
      end if
      end tell
      return (currentFolder as alias)
    end findFolder
    And here's a page where they explain how to use automator and the Services to do what I <allmost> want, with some adaptation.
    But it still doesn't work.
    http://hbase.net/2011/08/17/move-selected-files-into-a-new-folder-using-applescr ipt-and-automator/
    So if anybody has an idea n how I could do this ?
    It It could either be a folder action (I drag and drop the files into a folder and boom, they get their folder around them)that I would set on a folder on a network drive, or locally, it doesn't matter, or a service (right clic on the file and boom folder around it.
    So if anyone could help with this I'd be grateful...

    Hi,
    Make an Automator Service (Service receives selected "Files or Folders"  in the "Finder.app").
    Use this script in the "Run AppleScript" action:
    on run {input, parameters}
        tell application "Finder"
            repeat with aFile in input
                if class of (item aFile) is not folder then
                    set {tName, fileExt} to {name, name extension} of aFile
                    if fileExt is not missing value and fileExt is not "" then
                        set tName to text 1 thru -((count fileExt) + 2) of tName
                        tell (get container of aFile)
                            if not (exists folder tName) then make new folder at it with properties {name:tName}
                            move aFile to folder tName
                        end tell
                    end if
                end if
            end repeat
        end tell
    end run
    This script work on files with a name extension.

Maybe you are looking for

  • Since iOS 8 my purchases disappeared and I cannot re-download them!

    Since iOS 8 my purchases disappeared and I cannot re-download them!  I have tried going to purchased items and hitting the download from icloud icon.  It just says downloading, then goes back to the download icon. I have tried syncing from my Mac - s

  • The 'Music' app no longer remembers the place when playing Audiobooks.

    I have been downloading Audiobooks from Audible to iTunes for around 10 years. I always ensure that the settings include 'remember place' before uploading them to 'Music' on (currently) my iPhone 4. In the last few weeks this seems to have stopped wo

  • Start Up freezes just past grey Apple Screen---

    MacPro w/a 10.4.11 and 10.5 partition. Hangs trying to boot into the 10.4.11 Partition. Tried starting in SafeBoot mode, but won't accept password (yes, entering it correctly). So, started in 10.5 partition and ran Disc Utility, Disc Warrior--couple

  • Does script ui have anything similar to  measurement editboxes in dialogs?

    I'm looking for a edit boxes in script ui that take care of unit conversion, math execution, and error correction like the core indesign input fields and measurement editboxes in dialogs. I haven't found anything in my search. Can anyone point me in

  • Is this the answer?

    "Using a computer's browser, log into icloud.com.  You can't log into icloud.com using an IOS device." It this accurate information? I found it as I was doing a search to see why I don't have the login screen on my iPhone and iPad after IOS 7 update.