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.

Similar Messages

  • 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

  • Use Automator to move files and folder structure to another folder, retaining destination contents

    I have been struggling trying to setup Automator to move files and folder structure to another folder, retaining the destination contents.  Basically, I need to add files at the destination, within the same folder structure that exists at the source.  Here's some details about the scenario:
    -I have PDF files that I create on a seperate computer than I my daily use machine
    -For security reasons, the source computer doesn't have access to any shares on the destination computer
    -The destination computer has access to shares on the source computer
    -I want to delete the original PDFs at the source after they are moved or copied
    I haven't been able to get Automator to move or copy the folder contents (files and subfolders) without dropping everything copied at the top level of the destination, resulting in many duplicate folders and a broken folder structure.
    So far I've only had luck getting this to work at the command line, but I'd really like to have this setup in Automator so that I could have either a service or application that I could use for any folder, prompting for the source and destination folders.  I'm a relatively new Mac user with limited Linux experience, so this is the command that I've cobbled together and currently accomplishes what I'm looking for:
    ditto /Volumes/SMB_Temp/SOURCE ~/Desktop/Documents/DESTINATION
    cd /Volumes/SMB_Temp/SOURCE
    find . -type f -name "*.pdf" -exec rm -f {} \;
    Thanks for any ideas!

    If you have a command-line syntax that works, why not just create an Automator workflow with a single 'Utilities -> Run Shell Script' action, where that action has your (working) shell commands?
    Seems way, way simpler to me than trying to reinvent the wheel and transcribe shell commands into individual Automator actions

  • Everything on my desktop disappeared. i tried using the finder to locate specific files and they are missing. Help!

    i'm using a macbook pro retina, 2.4 GHz Intel Core i7, 8GB. operating OSX Yosemite 10.10.1
    everything on my desktop disappeared. i've managed to make my HD reappear on my desktop but my files etc are nowhere to be found. i tried using the finder to locate specific files and they are missing. Help! I foolishly filled up my desktop with piles of screen grabs and folders - no doubt that was the cause... what do i do, aside from punish myself for being so stupid?

    Could you have logged into another account?
    If you go to System Preferences>Users and Accounts what accounts are listed?
    To show users at login go to the Login Options of chanck the box that says show list of users.
    If they they are gone and you can't find them then restore them from a backup

  • Install Real Application Clusters (RAC) and Automated Storage Management (A

    Do I have to install Real Application Clusters (RAC) and Automated Storage Management (ASM) for ETL
    I have installed Oracle 10g Release 1 on WIndows 2000 with datawarehousing option.
    Is it ok
    Or do I need to install Oracle database again.
    Please help

    Greg,
    From what you describe you did exactly the right thing. The runtime platform service will by default run on DWH01, but you can shut it down on that node and have it run on DWH02 (in case you wanted to bring down DWH01 but still run Warehouse Builder processes). Note that we strongly recommend using the net service name in the location registration in the deployment manager (so that you automatically take advantage of the client-side load balancing feature of RAC (as well as the server-side load balancing)).
    Thanks,
    Mark.

  • I am using MS Office 2010 and Windows XP Professional, can I use iCloud for backup of my files and documents?

    I am using MS Office 2010 and Windows XP Professional, can I use iCloud for backup of my files and documents? I am planning to transition to a Mac so using the iCloud seems to make the most sence.

    No, it is not a backup method at all.  If you delete a sync'd file on any device, you delete it permanently from iCloud.  That by its very essence is not a backup solution therefore.  A backup solution does not automatically and simultaneiously delete the file everywhere when it is deleted from the original source.
    iCloud is strictly a syncronization tool for using files on multiple internet connected devices.

  • I transferred files and photos from MacBook to iMac via ethernet cable and using migration assistant. However every time I transferred, it created a separate user and it transferred all files and photos again and again. So now I have 3 users accounts ?

    I transferred files and photos from MacBook to iMac via ethernet cable and using migration assistant. However every time I transferred, it created a separate user and it transferred all files and photos again and again. So now I have 3 users accounts with all files and photos saved 3 times on same iMac !! Any idea how to avoid this ?

    Yes, you ran into a very understandable problem.
    When you use Migration Assistant, it cannot over-write the account that you happen to be using at the time. Upon migrating accounts, it will tell you that it is going to create a new one, but that message is easy to miss.
    If you have three identical accounts, log in to the account you want to keep, and delete the redundant ones in System Preferences > Users & Groups.
    Now that you know, the easiest way to migrate accounts is to use Setup Assistant when you first get a new Mac. That eliminates any possibility for this to occur, but most people are so eager to use their new Mac that they elect to migrate later.
    That's OK too, but in that case you would want to create a temporary account whose sole purpose is to run Migration Assistant so that you may migrate your old one with an identical name. Be sure to give the new account Administrator privileges. When that finishes you would log in to the newly migrated account, and delete the temporary account.

  • Hi... I would like to purchase a Tablet Sony Xperia Z 2 10.1 (the last one of the Z series) and I was told that Adobe does not support Sony anymore.... I need to be able to open and read Adobe PDF files and I would like to know if this tablet can still us

    Hi... I would like to purchase a Tablet Sony Xperia Z 2 10.1 (the last one of the Z series) and I was told that Adobe does not support Sony anymore.... I need to be able to open and read Adobe PDF files and I would like to know if this tablet can still use Flash Player...
    Is there anyo who can help me with this? I asked in the shop and I was told "yes of course" , but when I contacted Sony directly I was advised to check with Adobe as apparently in the recent months Adobe and Sony haven't been getting along anymore...

    You may be mixing up two entirely different Adobe products.
    1. Adobe Flash Player. Needed to view web pages designed with Flash. Not needed to view PDF files. Not available for Android (not just Sony).
    2. Adobe Reader. Reads PDF files. However, the Android can also read most PDF files without needing Adobe Reader.

  • Connect the device to your computer. Open iTunes. Select iPhone, iPad, or iPod in the Devices list. Click the Summary tab and select "Manually manage music and videos". Click Apply. but after that say's everything on my iPhone will be deleted

    Connect the device to your computer.
    Open iTunes.
    Select iPhone, iPad, or iPod in the Devices list.
    Click the Summary tab and select "Manually manage music and videos".
    Click Apply.
    than it says it'ss erase my iphone and sync with itunes library.
    what should i do?

    It wil only erase the music and videos. Nothing else.

  • Managing Files and Duplicates

    i'm new to iphoto and made the mistake of not unchecking the "make duplicate" preference when i imported my photos from folders on my hard drive. that means i now have a lot of duplicates to clean up, with photos taking up twice as much HD space as they need to.
    after doing some research it seems that many people advise that you should store and manage originals yourself rather than letting iphoto do it and risk possible corruption. is this correct ?
    in this case, presumably i should trash and empty trash in iphoto for all the photos i've already imported - an action that presumably will not affect the original copies stored in other files on my HD - and then re-import them into iphoto without making duplicates.
    does this all make sense as a sensible way to proceed ?
    thanks !

    Mark
    It's helpful to distinguish between the photos and the files that contain them. The Finder is a file manager, iPhoto is a photo manager.
    When you use iPhoto it's your Photo Manager - that is, it's your first point of interaction with your pictures. In this it replaces the Finder so, if you use iPhoto this
    if i then have all my images imported into iphoto that whenever i alter one - in photoshop for example - do i have to do this via iphoto rather than just opening the image in photoshop from the folder ?
    happens whether on not iPhoto manages the files, because iPhoto manages the photos. If you prefer to manage the files, if you don't distinguish between files and the photos they contain, then, simply, don't use iPhoto.
    You can set Photoshop (or any image editor) as an external editor in iPhoto. (Preferences -> General -> Edit Photo: Choose from the Drop Down Menu.) This way, when you double click a pic to edit in iPhoto it will open automatically in Photoshop or your Image Editor, and when you save it it's sent back to iPhoto automatically. This is the only way that edits made in another application will be displayed in iPhoto.
    When you import a pic into iPhoto the app copies the pic into the Library and then makes a thumbnail of it. If you subsequently edit the pic then there is a Modified version too. So iPhoto can have up to three versions (not copies) of the photo.
    It is strongly advised that you do not move, change or in anyway alter things in the iPhoto Library Folder as this can cause the application to fail and even lead to data loss
    FYI There are many, many ways to access your files in iPhoto:
    For 10.5 users: You can use any Open / Attach / Browse dialogue. On the left there's a Media heading, your pics can be accessed there. Apple-Click for selecting multiple pics.
    Uploaded with plasq's Skitch!
    To upload to a site that does not have an iPhoto Export Plug-in the recommended way is to Select the Pic in the iPhoto Window and go File -> Export and export the pic to the desktop, then upload from there. After the upload you can trash the pic on the desktop. It's only a copy and your original is safe in iPhoto.
    This is also true for emailing with Web-based services. If you're using Gmail you can use THIS
    If you use Apple's Mail, Entourage, AOL or Eudora you can email from within iPhoto. With 10.5 you can access the Library from the New Message Window in Mail:
    Uploaded with plasq's Skitch!
    If you use a Cocoa-based Browser such as Safari, you can drag the pics from the iPhoto Window to the Attach window in the browser.
    Or, if you want to access the files with iPhoto not running, then create a Media Browser using Automator (takes about 10 seconds) or use THIS
    Other options include:
    1. *Drag and Drop*: Drag a photo from the iPhoto Window to the desktop, there iPhoto will make a full-sized copy of the pic.
    2. *File -> Export*: Select the files in the iPhoto Window and go File -> Export. The dialogue will give you various options, including altering the format, naming the files and changing the size. Again, producing a copy.
    3. *Show File*: Right- (or Control-) Click on a pic and in the resulting dialogue choose 'Show File'. A Finder window will pop open with the file already selected.
    Regards
    TD

  • Managing files and directories

    I have a palm tx and am lost on how to transfer files back and forth between pc and palm. The syncing process seems to work for the applications but I would like to select files and transfer them to the palm and be able to create directories and manipulate files on the palm. How is this done?
    Post relates to: Palm TX

    johhfin wrote:
    I am trying to install doom(game) to the palm. The instructions are below and mention to bring a file or two over using hotsync. Seems that hotsync on my palm is automated, ie when I push the button on the usb is just downloads preset items. Is there a way I can hotsync just one file to a certain location?
    1/ install zdoomz.prc to your device
    2/ at first launch, it will create the needed directory (/PALM/Programs/ZDoomZ) & register
    the .zdk extension for itself.
    The link between .zdk files & /PALM/Programs/ZDoomZ is LOST after each reset & if another
    software register it -zquake, zhexen, ...-
    Run the launcher each time before a hotsync of a zdk file to be sure it goes in the right folder
    3/ copy "zdoomz.zdk" in the previous folder /PALM/Programs/ZDoomZ, or hotsync it.
    4/ copy your WAD file in the /PALM/Programs/ZDoomZ
     using either a smart card reader or the "mp3" trick => check http://www.zodiacgamer.com
     forum for more details.
    5/ if you want sound, install the gus patches in /PALM/Programs/Timidity
     The instructions are pretty clear (to me), but I question #3 about HotSyncing the .zdk file.  Just copy it as instructed.  The only file going to RAM is the .prc file, all the rest go to the SD card.
    I would HotSync the zdoomz.prc file only (to the device), then after it creates all the folders mentioned (on the SD card) use a cheap card reader to install all the other files directly to your SD card. (Remove it from the TX)  Once reinserted, run the ZDoomZ program file.
    Now whether you can get a decent copy of Doom to run on a Palm device is another story... Are you putting this on a Zodiac or your TX?
    WyreNut
    Message Edited by WyreNut on 08-27-2009 06:40 AM
    I am a Volunteer here, not employed by HP.
    You too can become an HP Expert! Details HERE!
    If my post has helped you, click the Kudos Thumbs up!
    If it solved your issue, Click the "Accept as Solution" button so others can benefit from the question you asked!

  • My macbook pro (using lion os) can't search files and folders on external hard drive! How can i solve it?

    When i used Snow leopard, i can search every files and folders on my external hard drive (NTFS). But when i upgraded to lion OS, sportlight didn't index files on exteranal hard drive and i can't search everything on external hard drive whatever i type in the search box! I also check the Finder preference and select when performing a search to "Search the current folder" ! How can i solve this problem! Please help me if you know!

    iTunes>Preferences (Cmd+,)>Advanced
    Choose the Ext HD (and the appropriate folder) as the location for your library.

  • Managing files and vaults

    Im in real trouble understanding this. I have a mac pro with 2 internal drives and 1 external. I want to have my entire managed files in the apperature library with 2 vaults. 1 on the extra internal drive and 1 on the external. My problem is when I import a raw file (I only shoot RAW) into apperature a project is created and a badge is created saying that the file(s) are referenced. The meta data shows the master being in the project so Im confused. Im also freaked out because I understand that the vaults do not retain referenced images. Is there a way to view the contents of a vault without doing a library restore? How can one be comfortable with these vaults if you cant view them. If I double click it apperature opens but its my regular library. So what I have done is selected every file 7k+ and consolidated the masters (copy) and then updated the vault which took a while so that kind of confirms my fear. The badges went away. any thoughts or a better way?

    It sounds as though you're missing the option, in the Import pane, to move the images into the Aperture library. That will make them "managed," which will mean they're including in the Vault. If you leave them "referenced" they're not in the Vault and Aperture won't do anything at all about backing them up -- that will be up to you.
    If your images are all referenced (they don't all have to be one or the other), what Aperture puts in the Vault is all the work you do on the images, in Aperture -- a set of recipes for how to process the images for display etc, not the images themselves.
    All this is covered in the manual and, better, on Bagelturf:
    http://homepage.mac.com/bagelturf/aparticles/ref/ref.html
    for example.

  • I can't manage file and storage services in server manager.

    I have a windows 2012 R2 server. I had turned on the file and storage services role and was able to configure a single share in server manager. A few days later I wanted to create another share but when I select file and storage services within server manager
    I get the message at the top that says The server has not been queried for data since it appeared offline. Also there are no shares listed. Even though the shared folder that I already created is available from other computers.
    If I try to create a file share anyway I am asked to choose a server to create the share on and the server appears in the list with a status of offline. 
    Now this may seem like an obvious connection issue however, I am trying to configure the server locally, not over the network. I can manage other services in server manager just fine. I have WDS and WSUS roles installed and can be configured with server
    manager just fine. I only have a problem with file and storage services. 
    There are no errors in the event log. 
    I tried to remove the file and storage services role from the server but as soon as I uncheck the box for file and storage services I get a pop up windows that says: 
    The validation process found problems on the server from which you want to remove features. The selected features cannot be removed from the selected server. click ok to select different featres.
    I lists validation results that simply state the name of the server and says "storage services cannot be removed."
    How can I get file and storage services working again?

    Hi,
    How many servers are there in the list? If the offline serve is a remote server, please reboot the remote server to see the result. In the meantime, please new a shared folded on the local server in Windows Explorer to see if the issue still exists.
    Please refer to the article below to share a folder with server manager.
    12 Steps to NTFS Shared Folders in Windows Server 2012
    https://blogs.technet.com/b/keithmayer/archive/2012/10/21/ntfs-shared-folders-a-whole-lot-easier-in-windows-server-2012.aspx#.Ux1ty_mSwXV
    Regards,
    Mandy
    We
    are trying to better understand customer views on social support experience, so your participation in this
    interview project would be greatly appreciated if you have time.
    Thanks for helping make community forums a great place.

  • Can I take a managed file and link it to a referenced file?

    Is this possible?
    I am creating a referenced library. Going forward, I know that I need to use only the referenced file to make new versions within Aperture.  But going back through my old files, I have originals and then all the edited copies.  These are only linked together in my head, because my practice was to make a copy of an original before working on it, so when Aperture imports it, it sees my copy as a new "original". I wondered if it is possible to reestablish any kind of link between my edited copies and the actual original file.
    Thank you.
    LCA

    Sorry not possible. To Aperture every file imported is an original (master). There is no way to say this import is a version of that original.
    You can come close using keywords and possibly stacks. It's not exactly what you are looking to do but at least you'll be bale to locate and group all similar images.

Maybe you are looking for

  • Include external html trough code in a custom tag

    Hi, I have a custom tag. The component class (say MyComponentUI) for my custom component extends UIComponentBase. I want to include an external html page, which url is formed using the content of an attribute of my tag (for example, the "value" attri

  • Does Photoshop support N-Color ICC profiles for soft proofing?

    Hi All, Does Photoshop support N-Color ICC Profiles for soft proofing? If yes, then can anyone guide me? Thanks!

  • Safari Favorites back up?

    Hi: I'm new to OSX, in this case Tiger. Up until a couple of days ago, I've been using Explorer in OS 9 and this browser-OS combination neatly created a Favorites folder that was easily located and saved/copied to another disk for backup, or dropped

  • Upstream U2 is down at my cab

    Hi, checked my stats this morning to find that my modem had resynced, for somereason upstream path U2 as stopped, causing me to loose upload, ill post the stats, you can see the power on upstream is minus when it used to 4.5, and also you can see U2

  • Purchase Requistion : ME52n/ME53n Total Value

    Hi Is it possible to add a field next to the purchase requisition number or in the top quarter of the screen . I want to total the valuation price into the field. Thanks