Help with selecting files from script menu or drag and drop

I found this scale images applescript online. It works great when a bunch of files is dragged on top of the script but I would like it to also work when a folder or group of files is selected in the Finder and I activate it from the scripts menu.
I can't get my on run statement to work. I'm not really an Applescript guy so I'm really just asking if someone can help finish what I started in this on run.
-- save in Script Editor as Application
-- drag files to its icon in Finder
property target_width : 120
property save_folder : ""
on run
tell application "Finder"
activate
set folder_path to quoted form of (POSIX path of (the selection as alias))
set theItems to every file of folder_path
end tell
end run
on open some_items
-- do some set up
tell application "Finder"
-- get the target width, the default answer is the property target_width
set new_width to text returned of ¬
(display dialog "Target width:" default answer target_width ¬
buttons {"OK"} default button "OK")
if new_width as integer > 0 then
set target_width to new_width
end if
-- if the save_folder property has not been set,
-- set it to the folder containing the original image
if save_folder is "" then
set save_folder to ¬
(container of file (item 1 of some_items) as string)
end if
-- get the folder to save the scaled images in,
-- default folder is the property save_folder
set temp_folder to ¬
choose folder with prompt ¬
"Save scaled images in:" default location alias save_folder
set save_folder to temp_folder as string
end tell
-- loop through the images, scale them and save them
repeat with this_item in some_items
try
rescaleand_save(thisitem)
end try
end repeat
tell application "Image Events" to quit
end open
on rescaleand_save(thisitem)
tell application "Finder"
set new_item to save_folder & "scaled." & (name of this_item)
end tell
tell application "Image Events"
launch
-- open the image file
set this_image to open this_item
set typ to this_image's file type
copy dimensions of this_image to {current_width, current_height}
scale this_image by factor (target_width / current_width)
save this_image in new_item as typ
end tell
end rescaleandsave

When items are dragged to your script's icon they are passed in to the on open handler, so this triggers:
on open some_items
and the dragged items are passed in as some_items
In contrast, when you double-click on the script, or invoke it via the Script menu, this runs the on run handler:
on run
  tell application "Finder"
    activate
    folder_path to quoted form of (POSIX path of (the selection as alias))
    set theItems to every file of folder_path
  end tell
end run
However, there's nothing in this block that actually does anything with the selection - you (dangerously) assume that the selection is a folder (you really should check first), and just set theItems to every file in that folder then you exit.
So to do what you want you'll need to edit your run handler to filter the selection and pass files over to the code that does the hard work.
You already have the basis for this - your rescaleandsave() handler, so it's just a matter of identifying the files in the selection and passing those over to that handler:
on run
  tell application "Finder"
    set cur_selection to (get selection) -- get the selection
    repeat with each_item in cur_selection -- iterate through
      if class of each_item is folder then -- do we have a folder?
        set theFiles to every file of each_item -- if so, get its contents
        repeat with each_file in theFiles -- iterate through them
          my rescaleand_save(eachfile) -- and process them
        end repeat
      else if class of each_item is document file then -- do we have a file selected?
        my rescaleand_save(eachitem) -- if so, process it
      end if
    end repeat
  end tell
end run
So the idea here is that the run handler gets the selection and works through the (potentially-numerous) items. For each selected item it checks whether its a folder or a file, if its a folder it gets all the files within and passes them to the rescaleandsave handler.
Note that this is not recursive - it won't catch files within folders within folders - since it only looks at the top level of selected folders, but it wouldn't be hard to rework the script to handle that if that's what you need.

Similar Messages

  • Working in Logic 9, how do I use a drum loop WITH ITS PRESET EFFECTS? I can drag and drop the loop but it plays dry in timeline. thanks

    Working in Logic 9, how do I use a drum loop WITH ITS PRESET EFFECTS? I can drag and drop the loop but it plays dry in timeline. thanks

    Here's the short-cut solution:
    Green Apple tracks are MIDI files (so to speak). If you drag one from the loop browser (Capitol C Orchestral hit, as you mentioned in this exable) directly into the arrange page it creates the MIDI file and the instrument to play it back on.
    HOWEVER.If you create and audio track first, THEN drag the green Apple loop onto that track, the loop will get "bounced" with the reverb in tact and you'll have the exact sound that you heard in the preview.
    Make sense?

  • IPhoto file creation date inconsistencies during drag and drop

    I have noticed that if I drag and drop a photo from iPhoto to Finder, the file creation dates in Finder are inconsistent.
    (This question is related to drag and drop only and not File->Export, which always uses the export date and timestamp for the file creation date and thus does not suit my needs).
    TEST A -- If the EXIF DateTimeOriginated is 01/01/2013, and today's date is 03/03/2013, then:
    In some cases when I drag a file to Finder, the EXIF date is used as the file modification/creation date in Finder
    In some cases, today's date is used as the file modification/creation date in Finder
    In some cases, a date in between the EXIF date and today's date is used
    It appears that for case A1, these are files that do not have a modified copy.  That is, if you select the photo in iPhoto and then click "File" -> "Reveal In Finder", the "Modified File" choice will be greyed out.
    For cases A2 & A3, iPhoto has inexplicably decided to create modified versions of these files either today or sometime in the past.
    TEST B -- I have read that unexplained modifications are tied to the auto-rotate function in cameras, and it does seem to be the case when I performed the test below:
    Select a large group of landscape format photos (these would not have been auto-rotated), then drag and drop to Finder.  The file creation dates are set to the EXIF date
    Add some portrait photos to the group in (1).  Now the file creation date of ALL photos including the non auto-rotated photos are set to the current date
    The behaviour in B2 is clearly wrong, since the landscape photos should be the same as in B1.  This is bug #1.
    Furthermore, iPhoto appears to be inconsistent with when these modifications are made.  For example, I dragged & dropped an auto-rotated photo on 02/02/2013, then dragged & dropped it again today, then the file creation date in Finder (and also the date of the modified file in iPhoto, as shown in iPhoto File->Reveal In Finder->Modified File) can either the EXIF date (01/01/2013), the late of the last drag & drop (02/02/2013), or today's date (03/03/2013); there does not appear to be any rhyme or reason to this.  This is bug #2.
    In any case, saying "you should never use drag & drop in iPhoto" (as I have read in some other forum posts) isn't a solution, because Apple should either (a) support this function correctly or (b) remove it altogether.  Furthermore, I regularly burn photos to disk for others so having the file date and timestamps correctly set to the EXIF date helps keeping the photos sorted in the directory listings for multiple OS, so File->Export isn't a solution.

    File data is file data. Exif is photo data. A file is not a photo.  It's a container for a photo.
    When you export you're not exporting a file. You're exporting a Photo. The medium of export is a new file. That file is created at the time of export, so that's its creation date. The Photo within that file is dated by the Exif.
    There are apps that will modify the file date to match the Exif.
    The variation you're seeing is likely due to the changes in how the iPhoto library works over the past few versions. Drag and drop is handy, but is not a substitute for exporting, nor intended to be.

  • Open a File in a JTextPane via Drag and Drop

    Hi,
         I have a simple JTextPane in a Swing App on Windows XP. I would like to know if it is possible for me to be able to add the functionality such that I can drag a text file to the JTextPane and it would open the file inside the Pane. Is this possible? If yes then how do I implement it? (I am not insisting on the app working on non-Win XP systems � so portability is not a concern.)
         I have tried to search for the drag and drop stuff but I am confused. First, which interfaces should I implement i.e. DragGestureListener, DragSourceListener, DropTargetListener or what?
         I would be grateful for any pointers.
    Thanks a lot,
    O.O.

    1. http://java.sun.com/docs/books/tutorial/uiswing/dnd/intro.html - This link did have the information but has since been updated and no longer points to the relevant information that I have since used.
    So you where given a link with the appropriate informaton, but Sun has changed the information and you are blaming us for not helping? Unbelievable!
    Here is a link to the old tutorial:
    https://www.cs.auckland.ac.nz/references/java/java1.5/tutorial/uiswing/dnd/intro.html#importFiles
    Now tell us how that does not do exactly what you wanted?
    I really don�t know why some people waste their time here just providing you with linksBecause most people like yourself don't know how to ask a question. DnD is a complex topic. The only way to learn it is to read a tutorial and experiment. What a better way to learn than to play with a working example. You are given many working examples in the tutorial.
    You did not state wihich example you had changed. You did not state what problems you where having.
    The best you could state was "I'm confused". You where asked to clarify your problem/confusion but didn't. We are not mind readers so we couldn't provide further help.
    I agree I am wasting my time helping someone who doesn't even appreciate the effort made by the many individuals of the forum and I won't make that mistake again.

  • Combine Files Dialog 8.1.6--drag and drop broken?

    I just reinstalled Acrobat 8, and the Combine Files panel is "all whacky".
    If I drag one or more documents into the panel, they are added normally. But if I then add another batch of 1 or documents, the FIRST SET OF DOCUMENTS is added again.
    To be clear, if I drag documents 1.tif, 2.tif, and 3.tif into the Combine Files panel, I end up with (as expected)
    1.tif
    2.tif
    3.tif
    But if I then drag documents 4.tif and 5.tif into the panel (or any other set of documents), I end up with
    1.tif
    2.tif
    3.tif
    1.tif
    2.tif
    3.tif
    Adding files through the file chooser panel works fine. Can someone tell me if this is peculiar to my installation or if it is a bug in Acrobat Pro 8.1.6?
    Thx

    Sort of the same here:
    I just noticed that the standard "drag and drop" in combination with "cmd + tab" to switch applications no longer works on my MacBook Pro. Whenever I try to drag pictures (e. g. jpg) from Safari into a Keynote 09 presentation (switching from Safari to Keynote using "cmd + tab"), the dragged image simply hangs and cannot be dropped into Keynote.
    And here's the _truly weird_ thing:
    When I then use "cmd + tab" again to switch to the next app again, the Keynote window stays on top and I can suddenly move and drop the dragged picture again. How strange is that?

  • I have 9.0.1 on 2 pc's, both xp sp3. On 1 the 'open new tab' button is visible, on the other, the 'open new tab' button is not even available in the 'customize toolbar' menu for dragging and dropping. Why?

    I used the same installation file, but on 1 pc, the 'open new tab' button is available in the 'customize toolbar' menu and can be dragged and dropped onto the navigation bar. On the other pc, the 'open new tab' button/icon is not even available for dragging and dropping. I uninstalled firefox completely, including settings and preferences, then reinstalled, but that did not correct the missing button.

    Hi,
    Please try '''Restore Default Set''' in the '''Customize...''' window. If it's still not visible, one reason could be that the button is already placed on the toolbar but may be hidden behind another icon or toolbar.
    Useful links:
    [https://support.mozilla.com/en-US/kb/Options%20window All about Tools > Options]
    [http://kb.mozillazine.org/About:config Going beyond Tools > Options - about:config]
    [http://kb.mozillazine.org/About:config_entries about:config Entries]
    [https://support.mozilla.com/en-US/kb/Page%20Info%20window Page Info] Tools (Alt + T) > Page Info, Right-click > View Page Info
    [https://support.mozilla.com/en-US/kb/Keyboard%20shortcuts Keyboard Shortcuts]
    [https://support.mozilla.com/en-US/kb/Viewing%20video%20in%20Firefox%20without%20a%20plugin Viewing Video without Plugins]
    [http://kb.mozillazine.org/Profile_folder_-_Firefox Firefox Profile Folder & Files]
    [https://developer.mozilla.org/en/Command_Line_Options#Browser Firefox Commands]
    [https://support.mozilla.com/en-US/kb/Basic%20Troubleshooting Basic Troubleshooting]
    [https://support.mozilla.com/en-US/kb/common-questions-after-upgrading-firefox-36 After Upgrading]
    [https://support.mozilla.com/en-US/kb/Safe%20Mode Safe Mode]
    [http://kb.mozillazine.org/Problematic_extensions Problematic Extensions]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20extensions%20and%20themes Troubleshooting Extensions and Themes]
    [https://support.mozilla.com/en-US/kb/Troubleshooting%20plugins Troubleshooting Plugins]
    [http://kb.mozillazine.org/Testing_plugins Testing Plugins]

  • Embed animate file in Dreamweaver, make the drag and drop stop working

    The drag and drop works fine when I open the Animate file, but when I embed it using the "Media > Edge Animate", it does not work. How can I solve this problem?
    I'm using an external js file.
    Thanks.

    Need you to share the dreamweaver project along with the edge animation, to check the issue.
    Regards,
    Vivekuma

  • Scripting Error in drag and drop of the UIelements

    Hi,
    This is ashwin ,iam new to webdynpro abap ,as iam started in uidevelopement trying to drag and drop uielement into layout its is showing error while iam dragging and droping the uielement like scripting error.
    can any one help mi what that scripting error could be rectified?
    Regards,
    Ashwin

    Hi,
    Thanks fo rthe reply ,i tried on st22 its showin no error .Iam getting a popup saying error as "__ERROR HAS OCCCURED IN THE SCRIPT OF THE PAGE".
    I am using IE 7 Browser and having high internet connection, iam not understanding why am i unable to drag and drop  UIElements on the layout ?
    Regards,
    Ashwin

  • ITunes 11.0.4 still copying files to media library after dragging and dropping while holding down "option"

    I'm having trouble adding media without automatically copying the file to the iTunes media libary after dragging and dropping while holding down "option."
    In Preferences > Advanced, "Copy files to iTunes media folder when adding to library" is checked. When I drag a file into iTunes while holding "option", the green "plus" icon disappears. However, iTunes still copies the file to media folder.
    Any suggestions?

    you can also try:
    I found that if I SCROLL down to the word 'playlist' and hover around the name, a 'show' comes up.  Click on the 'show' and everything magically appears.

  • Need some help with sharing files from a Mac G3 to a Mac G4

    I've read through some of the forum comments here and checked with help, but still have a great deal of trouble understanding how to share files between two computers, especially when one has OSX 10.3.9 and the other has 9.2.2. I have these two computers connected with a router, but just can't seem to pass files from my G3 to my G4. All of the instructions I read are very confusing- subnet mask, IP address etc. Is there an area I can go to to get a better understanding? It seems like this shouldn't be very difficult. Is there an inherent problem because of the different systems? Thanks for any help I can get.
    Dick Skover

    I printed the article from Francine, and followed all of the steps and it just doesn't work. Actually, one of the first steps is to go to AppleTalk under the control panels and select "Connect via Ethernet" which I did, but got a "no zones available in that box and no options shown in that box. Is there a problem with the fact that I am connected through a router? Should I have a direct connection between computers without the router?
    I'm also reading the files sharing section of David Pogue's book on OSX The Missing Manual, but still can't get a handle on it. Any further help would be appreciated.
    Dick Skover

  • Selecting file from dropdown menu

    Hi,
    I've just converted a form from Excell into PDF. My original form had an option to open another page by selecting a file from a dropwdown, then hitting a button.
    Obviously the macro will not work in PDF, but is there another way in which I can open a specific file from a dropdown list. At the moment I am only able to open one file per button. I need to be able to scroll down, say A, B, C, D, E and then select which number I want to open.
    Any help is much appreciated.

    You can start here: http://www.adobe.com/devnet/acrobat/javascript.html
    But I should warn you, it's very different from VB, and it could be complex.
    Good luck, though.

  • Help with pulling files from PlayBook

    I have been trying for a while now to pull the files from my husbands PlayBook that has a corrupt OS per BB phone support. I had pretty much come to this conclusion but had to hear it from someone else before I decided this too. Well....per BB support someone, probably one of the kids, tried to do an update via WiFi and lost the signal while doing so which corrupted the OS. It needs to be repaired and doing so, as we all know, will dump the files/data on the PB. Really bad thing is my husband has NEVER....dont want to say I told you so.....synced the PB and there are videos and photos we can't lose on it. We would rather keep the PB as it is and buy another than repair the OS and lose the data. What I have found out is that the main means of communication for the PB are corrupt as well which doesn't allow us to connect to WiFi or BB Bridge. The PB will find my Storm 2 via bluetooth and I can tether it to the internet that way. I am now stuck! When it tethers and I pull up Google it automatically logs into my husbands Google account. I then try to click gmail and the bar gets halfway across the top and then stops. It does this most of the time. I have been successful in sending myself an empty email but when I try to email the photos and videos it says I can't attach the files because they are too big. Even 1 photo it states the file is too big? I also have a box.com account that I can't get logged into? I am guessing because it really needs to read the site as a mobile site and can't. I am hoping that I am really being too impatient and need to wait longer than 5 minutes for these sites to try and load because I am tethered through my phone? Any suggestions would be greatly appreciated. I was sure this was a lost cause but now that I can tether through my phone I am hoping there is hope......  

    I have tried the hard reboot on several occasions. I spent over an hour on the phone with BB support and they are the ones that told me the OS was corrupt. The PB is a 32 GB and has a ton of data on it (410 videos, 2595 pictures) but the strange thing is the readings I am getting. Total Storage 0 bytes and Free Storage 3.5 GB and then Total Memory 0 bytes and Free Memory 641.5 MB and Boot Time is blank with no reading at all (these readings seem backwards to me??). I have compared it to my PB which is working properly and I, of course, have a boot time. On other forums I have been told that these readings mean the PB is full and can't process data and to delete some of the files...well, it wont let me delete anything, not even 1 picture.
    I don't get an error message when trying to connect to WiFi. It just spins on the attempt 1 of 3 and never connects or tells me it has timed out. I have done every option I can to connect. I have even deleted the networks from my PB and taken the same steps with both and mine connects automatically like it should. I have tried connecting it to different computers and different networks.
    The reason for the assumption of a corrupt OS is that I can't get it to manually network map to any computer. I have tried with the PB network name and with the IP address of the PB. No computer will find it but taking the same steps with my working PB and everything connects as it should.
    Here is another funny thing. If the PB is connected via USB to my laptop and the BB Desktop Software is open eventually it will find the PIN number of the PB but it constantly pops up the error message that the PB is not connected, will not connect, and that it needs to be repaired BUT.....it will pull up the PB on the Desktop Manager but wont connect to the computer at all. When it does find the PIN number on the Desktop Software it does not allow me to click sync or anything because technically it is not connecting and reading data from what I can tell.
    The real question, I think, and I haven't had time to try, is can I add an app via App World if I can't open apps?

  • Mac Virgin!  Need Help with migrating files from PC

    I am currently waiting for my Mac to be shipped to me and want to be prepared to transfer all of my PC files over once it gets here. I need to know if I need a cord of some sort (USB?) to connect the PC and Mac in order to do this.
    Thanks!

    Hi Winnie7779,
    If you purchased the MBP from Apple, you can take it and your PC to your local Apple Store, and they will transfer the files for you. If this is not an option, you should probably pick up a copy of Switching to the Mac The Missing Manual (http://oreilly.com/catalog/9780596514129/index.html). This book was in invaluable resource for my switch earlier this year. It will answer many of your questions, and give you an offline resource to browse. As for your design files, if the program you used on Windows has a Mac version, the file shouldn't need any conversion, and will just open in the native program. In the case where there is no native program, the Mac version may have its own importing option. If there is no comparable Mac program, there is not much you can do on the Mac side. Fortunately, all recent Macs can run Windows, using a program like Parallels Desktop for Mac (http://www.parallels.com) or VMWare Fusion (http://www.vmware.com/products/fusion/). These programs allow you run Windows in a window on the Mac Desktop, and then you could run your WIndows programs directly and use the files that way. Another and cheaper alternative is to use Boot Camp, which is included with Leopard, this will allow you to reboot and turn your Mac into a fully featured Windows PC. Good luck!
    Rich S.

  • Need help with loading files from Sony cam!

    How can I import files from a Sony DCR-SR100 camera into FCP 6.0.1?
    Will it work with the Log&Transfer function?
    Camerainfo here:
    http://www.sony.no/view/ShowProduct.action?product=DCR-SR100E&site=odwnoNO&pageType=Overview&imageType=Main&category=SDHHard+DiskDrive

    FCP does not currently support HDD camcorders. For a more detailed explanation, check out this:
    http://discussions.apple.com/thread.jspa?messageID=4719805&#4719805
    The only solution I can think of that might (might) work is to import using iMovie 08, which claims to support certain HDD cams, and transfer into FCP.

  • Help with transferring files from Windows to MacBook Pro

    Just got a new MacBook Pro and need to transfer files from a very old Windows operating machine. Have the Seagate Slim portable drive.  I downloaded the online software to format it for the windows files (taking 4 hours).  Now, I'm told it will not work on the Apple product.  Has anyone used this and had success? Or is there an easier way?

    Hello CharliePaints,
    Thank you for using Apple Support Communities.
    For more information, take a look at:
    Switch Basics: Migrate your Windows files to your Mac
    http://support.apple.com/kb/ht2518
    Transfer information from your PC over your wired or wireless network
    To move files using Migration Assistant to your Mac from your PC, use these steps.
    Have a nice day,
    Mario

Maybe you are looking for

  • A/V cable and Visio

    Is the creative A/V cable the only one that would work with the vision or other branded A/V cables would work too?I bought a regular one and it didn't work.Anyone knows of other place to buy the creative one except the creative online store?

  • Sensing a keyboard press in a forms app?

    In a windows form, I have a button. When that button is pressed, I want it to look for keyboard presses. When the spacebar is pressed 10 times, I want the button to do something. Is this at all possible? In Calculus, 1+1=0.

  • Smartforms in landscape layout

    Hello  Gurus ,                        I want to print test certificate in smartforms in landscape layout , i given inch12 in output options of form attributes , but i am getting print out in portrait form , is there any particular reason that i am no

  • How TimesTen works

    Hi, I am new to TimesTen. I would like to know how Timesten works. I have created a cache group on table test and have loaded it with 2GB of data. Now if I issue a query from sql plus will it execute on the cache group or from the database?

  • Search help to return multiple values

    Hi all, I've created a search help and I'd like it to return several values to different fields, I don't want these fields to be seen on the selection screen. For example: 1. User clicks on search help for FIELD1 and selects a value from the pop-up b