AppleScript "choose file" issue

This is not a question but instead a cross-reference to one I posted in the AppleScript forum about using the AppleScript command "choose file of type{}" & the URI's for iWork '08 application files. If you are an Applescript user, please take a look at it:
http://discussions.apple.com/thread.jspa?threadID=1673486
Thank you.

Responded in the original thread.
Yvan KOENIG (from FRANCE jeudi 21 août 2008 12:42:19)

Similar Messages

  • Applescript: choose file AND folder (multiple selection allowed)

    Hi all;
    is there any way to select files and folder with and apple script?
    I'm trying to write something to compress some stuff and I'd need this stuff to be both files and folders at once…
    Thank you!

    Plain AppleScript doesn't have that kind of dialog, but you can access various Cocoa methods in Snow Leopard and Lion.  In Lion, you create a Cocoa-AppleScript Applet from a template in the AppleScript Editor, where you can use AppleScriptObjC statements.  Since the script can only be run in the application and not the AppleScript Editor though, it is a little bit of a pain to troubleshoot - Shane Stanley has written an ASObjC Runner background application that can be run from the AppleScript Editor, if you wanted to check that out.
    Running the Cocoa-AppleScript template, you can use something like the following - see the NSOpenPanel Class Reference for other methods and settings:
    set defaultDirectory to POSIX path of (path to desktop) -- a place to start
    tell current application's NSOpenPanel's openPanel()
      setFloatingPanel_(true)
      setTitle_("Choose some stuff:")
      setPrompt_("Choose") -- the button name
      setDirectoryURL_(current application's NSURL's URLWithString_(defaultDirectory))
      setCanChooseFiles_(true)
      setCanChooseDirectories_(true)
      setShowsHiddenFiles_(false)
      setTreatsFilePackagesAsDirectories_(false)
      setAllowsMultipleSelection_(true)
      set theResult to it's runModal() as integer -- show the panel
      if theResult is current application's NSFileHandlingPanelCancelButton then quit -- cancel button
      set theFiles to URLs() as list
    end tell
    repeat with X from 1 to (count theFiles) -- coerce the file paths in place
      set (item X of theFiles) to (item X of theFiles)'s |path|() as text -- as POSIX file
    end repeat
    choose from list theFiles
    if result is false then quit

  • AppleScript System Events Choose File Name Statement Broken?

    Re: OS X 10.9.2, AppleScript Editor 2.6.1:
    Why does the following AppleScript statement hang the Script Editor?
    tell application "System Events" to ¬
      choose file name with prompt "Output File" default name "Output File" default location (path to desktop)

    see Applescript Release Notes, Scripting Addition Security.
    Applescript, unlike other scripting languages, relies heavily on functionality being provided by client applications. This makes it much harder to keep consistent behavior across different contexts, because it's up to individual providers to implement applescript commands. A fact of Applescript life.
    However, it seems your real problem is not with System Events, but with the fact that your dialog is getting lost off-screen. This works:
    tell application "System Events"
      activate
      choose file name
    end tell

  • Applescript: Choose two files in different locations

    Hello there, trying to combine multiple CSVs into one.
    When I run this applescript, I can only choose multiple files within the same folder.
    How to I change it so I can choose file A.csv in folder X, and then file B.csv in folder Y?
    set theFiles to choose file with multiple selections allowed
    set saveFile to POSIX path of (((path to desktop) as text) & "Hello.csv")
    do shell script "cp " & quoted form of POSIX path of item 1 of theFiles & space & quoted form of saveFile
    if (count of theFiles) = 1 then return
    repeat with fileToAdd in theFiles
              set x to quoted form of POSIX path of fileToAdd
              do shell script "cat " & x & " | awk 'BEGIN {getline}{print $0}' >> " & quoted form of saveFile
    end repeat

    Quick followup question, if you have time.
    When I try to merge files using this method, I get duplicate entries in my CSV.  For example:
    file1.csv + file2.csv resultes in mergedfile.csv
    When I try to merge mergedfile.csv with file3.csv, I get duplicate entries within the CSV of file1.csv & file2.csv
    For example (pre-merge):
    file1.csv
    hello, greeting, "hello how are you"
    hi, greeting, "hi, what's new?"
    file2.csv
    apple, fruit, "I like apples"
    banana, yellow fruit, "i eat banans"
    file3.csv
    britney spears, pop singer, "britney is a good singer"
    celine dion, better pop singer, "celine is better"
    Merging file1 and file2 Results in:
    mergedfile.csv
    apple, fruit, "I like apples"
    banana, yellow fruit, "i eat banans"
    hello, greeting, "hello how are you"
    hi, greeting, "hi, what's new?"
    When mergedfile.csv is merged with file3.csv:
    mergedfile.csv
    apple, fruit, "I like apples"
    banana, yellow fruit, "i eat banans"
    hello, greeting, "hello how are you"
    hi, greeting, "hi, what's new?"
    apple, fruit, "I like apples"
    banana, yellow fruit, "i eat banans"
    hello, greeting, "hello how are you"
    hi, greeting, "hi, what's new?"
    britney spears, pop singer, "britney is a good singer"
    celine dion, better pop singer, "celine is better"
    Any help would be appreciated greatly!

  • Applescript: color file name in finder

    Hi Community,
    I'm working on a huge data management program and i want to be able to tag certain files with incorrectly inputed data so i can easily go back to them later. Rather than moving them all to a certain place, I was wondering if, with applescript, there's a way to color their labels. Hopefully without clicking. Thanks.

    It's trivial to set the label of a file:
    set theFile to (choose file) -- or however you're identifying your file
    tell application "Finder"
              set label index of file theFile to 3
    end tell
    where 'label index' is the index to the labels on your machine.
    The issue is how to identify which files to change.

  • Applescript open file in hidden folders

    When a folder is made visable and finder is reset  then activating applescript to open file in folder, the once hidden folder but now visable in finder doesn't appear.
              do shell script "defaults write com.apple.finder AppleShowAllFiles False"
    -- kill Finder to make the changes active
    do shell script "killall Finder"
    then activate Applescript Editor and open file and the folder but folder will not appear.

    Aha, this seems to work, but I'm not sure why:
    set the_file to (choose file) as text
    tell application "Adobe Photoshop CS5"
        open file the_file
    end tell

  • Applescript new file

    Hi everybody
    I am quite new to Mac and new to programming.
    I am learning Applescript. I am trying to write a simple script that I can add to the title bar of Finder.
    I want the script to show a choose file box where I input the name of a file to create and choose the destination to save it to.
    Then click ok and it saves it where I want and as i want including Tags
    I can do the first part, show the choose file name with properties. the problem I have is how to get Applescript to then save it where I want.
    The best I can do so far is to have the script saved as what I want but only in the default location which is set to desktop. How do I get Applescript to get the location of where I chose and put it into a variable so that I can then tell Applescript to make new file at the variable with the name entered in the choose file name box
    Any help would be grateful
    Thank you

    Once you have the result from choose file name you can use open for access to create the file, followed by write to write data to it, and close access to clean up when you're done:
    -- prompt the user for the file name:
    set fn to choose file name
    -- open (and create) the file:
    set f to open for access fn with write permission
    -- write some data to it:
    write "blah" to f
    -- and close it when you're done:
    close access f
    So I think 'open for access' is the part you were missing. It creates the file if it doesn't already exist, otherwise it allows you to overwrite/append data to an existing file.

  • Choose file name in Snow Leopard

    In Leopard, when I run the StandardAdditions command *choose file name* and I click on an existing file listed in the resulting *Choose File Name* dialog, the +entire file name including file extension+ is placed into the *Save As:* text box, and that is what is returned when I click the Save button.
    In Snow Leopard, when I do the same, only the file’s +base name+ is placed into the text box, and only the +base name+ is returned.
    I need the Leopard behaviour.

    hungryjoe wrote:
    Appending a filename to the returned result is rather trivial
    Trivial? Consider, in Leopard and before:
      |    set f *to choose file name*
      |    +(* At this point, f is a file specifier and exactly one of the following is true:+
      |          +• the file specified by f does not exist; or+
      |          +• the user wants to overwrite the file.+
      |     +And the file specified by f is exactly what the user chose. *)+
    That’s one line. Compare that to Snow Leopard:
      |     property FileNameExtension : ".pdf"
      | 
      |     repeat
      |           set f to +POSIX file+ ((POSIX path of ( *choose file name* )) & FileNameExtension)
      |           try
      |                 alias f
      |           *on error* number -1728 +-- can’t get reference; i.e. file does not exist+
      |                 *exit repeat*
      |           *end try*
      |           try
      |                 tell application "System Events" *to get the* name *of the* result
      |                 *display alert* "“" & the result & "” already exists. Do you want to replace it?" ¬
      |                       message "A file or folder with the same name already exists. " & ¬
      |                             "Replacing it will overwrite its current contents." ¬
      |                       as warning ¬
      |                       buttons {"Cancel", "Replace"} ¬
      |                       default button "Cancel" ¬
      |                       cancel button "Cancel"
      |                 if button returned *of the* result is "Replace" *then exit repeat*
      |           *on error* number -128 +-- User cancelled+
      |                 +-- ask again+
      |           *end try*
      |     *end repeat*
      | 
      |     f
      |     +(* At this point, f is a file specifier and exactly one of the following is true:+
      |           +• the file specified by f does not exist; or+
      |           +• the user wants to overwrite the file.+
      |     +But the script has had to force a file name extension on the user,+
      |           +so the file specified by f is not actually what the user chose. *)+
    You might do it differently as a matter of style, but you can’t do it simpler and you can’t do it shorter.
    (Rant: do you have any idea how much fiddling it took me to come up with
      |           set f to +POSIX file+ ((POSIX path of ( …
    to work around the fact that AppleScript doesn’t do what the AppleScript Language Guide says on pages 43 and 88.)
    Perhaps you should file a bug report/feature request, however you see it at [http://bugreport.apple.com>.
    I’ll do that tomorrow.

  • "choose file name" loses the extension when clicking a file

    I'm using the "choose file name" command in a script but when I click on an existing file it loses the extension.
    Apparently the same problem as here:
    http://discussions.info.apple.com/message.jspa?messageID=10410632
    Is there a workaround for that ? Or is it just impossible to retrieve the needed extension ? (and we need to wait for Apple to fix that...)

    Hello
    Well, not that I know a work-aronud except for the obvious to type the extension manually...
    Since I cannot think of any good reason for the command's interface to drop the extension deliberately, I'd classify this as bug.
    You'd better send feedback to Apple requesting fix.
    *If you send bug report via bugreport.apple.com, you'd likely get duplicate notice saying that it has been already reported. So try general feedback channel :
    http://www.apple.com/feedback/macosx.html
    The more users want it to be fixed, the more chances for it to be fixed.
    Regards,
    H
    P.S. By the way, 'choose file name' command had not let user choose existing file (with existing files grayed out in dialogue). It is rather new feature letting user select existing file. Perhaps 10.5 (AppleScript 2.0) and later, I guess. Defect in new feature should be able to be fixed easily without breaking backward compatibility.

  • Applescript Moving files?

    So I'm using Applescript on on OSx Mavericks and i'm trying to emplement choosing files, moving files to the trash and then deleting them. I always get some sort of error where I select a photo off the desktop and instead, it moves the script i'm working on into the trash! can someome please review my code and help me out?
    set var to choose file with prompt "Choose a file to move. (⌘-click selects more than one)"
              set mySelection to selection of var
              tell application "Finder"
      move selection to trash
              end tell
              display dialog "I will now continue with the deleting process." buttons {"OK"} default button 1
              tell application "Finder"
                        empty the trash
              end tell

    I thought this solved it, but it keeps giving me this error when i select a picture:
    Can’t get selection of alias "Macintosh HD:Users:(InsertUserNameHere):Desktop:Screen Shot 2014-01-24 at 11.38.39 PM.png".
    Can you tell me why?

  • Applescript move files

    I have this applescript that when i place files in a folder on my desktop it will prompt me for a subject and email it to my gmail account. I wanted to add a line that would kick those file(s) back out to my desktop apon completion. It sends the files but will not proceed... if i run it in the script editor it does kick them out... why arent both of my commands running?
    [ code ]
    on adding folder items to thefolder after receiving theAddedItems
    repeat with eachitem in theAddedItems
    set theSender to "Me<[email protected]>"
    set recipCommon to "Files"
    set recipAddress to "[email protected]"
    set msgText to "Some text"
    tell application "Mail"
    set newmessage to make new outgoing message with properties {content:msgText & return}
    tell newmessage
    set sender to theSender
    display dialog "Please Enter a Subject:" default answer ""
    set theSubject to text returned of result
    set subject to theSubject
    make new to recipient with properties {name:recipCommon, address:recipAddress}
    make new attachment with properties {file name:eachitem} at after the last paragraph
    end tell
    send newmessage
    end tell
    end repeat
    end adding folder items to
    try
    tell application "Finder"
    move every file of folder "Macintosh HD:Users:home:Desktop:somefolder:" to folder "Macintosh HD:Users:home:Desktop:"
    end tell
    end try

    You can't run a folder action script in an open Script Editor window without substituting variables.
    A better solution would be to not even use a folder action to begin with, since you want the file to remain on your desktop anyway. This variation makes you select one or several files from a dialog while leaving the files intact:
    set theItems to choose file with multiple selections allowed
    repeat with eachItem in theItems
    set theSender to "Me<[email protected]>"
    set recipCommon to "Files"
    set recipAddress to "[email protected]"
    set msgText to "Some text"
    tell application "Mail"
    set newmessage to make new outgoing message with properties {content:msgText & return}
    tell newmessage
    set sender to theSender
    tell application "Finder" to display dialog "Please Enter a Subject:" default answer (name of eachItem as string)
    set theSubject to text returned of result
    set subject to theSubject
    make new to recipient with properties {name:recipCommon, address:recipAddress}
    make new attachment with properties {file name:eachItem} at after the last paragraph
    end tell
    send newmessage
    end tell
    end repeat
    Another possibility might be to make a "droplet", where you drop the file(s) on the script to send them.
    But the most elegant Mac-like solution is to use the Applescript menu.
    Enable the Applescript menu and you will have a fast convenient way to access any script for any application. There are some super cool tricks with Script Menu.
    To enable the Applescript Menu, open the application at
    /Applications/AppleScript/AppleScript\ Utility.app
    and select "Show Script Menu". The frontmost application (in focus) has its own script menu so it is always changing. You can create a folder for the frontmost application by clicking the menu icon, then selecting "Open Scripts Folder", then "Open ** Scripts Folder". A new empty window will appear ready for you to populate with Applescripts. That is too cool!
    Put your script in that folder and now whenever Mail.app is in front you have fast access to the script.
    But alas, selecting files from a dialog is not convenient enough for us Mac folk, so here is the easiest way of all.
    Replace the first line of the script with this one:
    tell application "Finder" to set theItems to the selection
    Now all you have to do is select (highlight) the files in any window and bring Mail.app to the front and click the Applescript icon. That is too easy!

  • Choose file without invisibles Leopard

    I'm having a problem with choose file without invisibles (Leopard).
    The line
    *choose file with prompt "Select a file" as string default location path to home folder without invisibles*
    shows an open dialog with all invisible files (those whose names start with a .) are visible.
    What's wrong?
    Is it a bug in Leopard Applescript?
    Something weird on my machine?
    Or is this what is supposed to be? If yes, how do I get no invisibles?
    Berend

    It's the literal way AppleScript interprets your command "path to home folder without invisibles"
    It assumes you're applying a parameter to "path to home folder", and if you use a parameter when one is not expected, it can be with or without anything.
    *path to home folder without kangaroos*
    Works and parses equally well, as does
    *path to home folder with sausages*
    But by including the braces you're isolating "path to home folder" and applying the "without invisibles" parameter to "choose folder".
    Cheers,
    H

  • The operation can't be completed because some items had to be skipped. For each item, choose File Get Info, make sure "Locked" is deselected, and then check t

    The following error comes up when I try to install the updated Firefox:
    "The operation can’t be completed because some items had to be skipped. For each item, choose File > Get Info, make sure “Locked” is deselected, and then check the Sharing & Permissions section. When you are sure the items are unlocked and not designated as Read Only or No Access, try again."
    When I follow the instructions in the error message, it shows that my user name has read and write access. There are a couple other items that are read only. I tried to change this to read and write, but the Sharing and Permissions options are greyed out and will not let me change them. What is the work around for this? I would really like to install the new firefox.
    Thanks.

    Hello,
    Certain Firefox problems can be solved by performing a ''Clean reinstall''. This means you remove Firefox program files and then reinstall Firefox. Please follow these steps:
    '''Note:''' You might want to print these steps or view them in another browser.
    #Download the latest Desktop version of Firefox from http://www.mozilla.org and save the setup file to your computer.
    #After the download finishes, close all Firefox windows (click Exit from the Firefox or File menu).
    #Delete the Firefox installation folder, which is located in one of these locations, by default('''This will NOT delete profile info such as bookmarks and history'''):
    #*'''Windows:'''
    #**C:\Program Files\Mozilla Firefox
    #**C:\Program Files (x86)\Mozilla Firefox
    #*'''Mac:''' Delete Firefox from the Applications folder.
    #*'''Linux:''' If you installed Firefox with the distro-based package manager, you should use the same way to uninstall it - see [[Installing Firefox on Linux]]. If you downloaded and installed the binary package from the [http://www.mozilla.org/firefox#desktop Firefox download page], simply remove the folder ''firefox'' in your home directory.
    #Now, go ahead and reinstall Firefox:
    ##Double-click the downloaded installation file and go through the steps of the installation wizard.
    ##Once the wizard is finished, choose to directly open Firefox after clicking the Finish button.
    Please report back to see if this helped you!
    Thank you.

  • I can't seem to open (view) my photos.  I get an error message that says "the file couldn't be opened because you don't have permission to view it. To view or change permission, select the item in the finder and choose File. Get info."

    I can't seem to open (view) my photos.  I get an error message that says "the file couldn't be opened because you don't have permission to view it. To view or change permission, select the item in the finder and choose File. Get info."  I have never had this happen before?  Thanks!

    Try the following:
    1 - launch iPhoto with the Command+Option keys held down and rebuild the library.
    2 - Run Option #1, Repair Permissions.
    OT

  • Saving a PDF file when printing is not supported. Instead, choose File Save.

    I am using Mountain Lion (10.8.2) and I was using Adobe Reader version 9. In the past, I've always been able to print to file using the File -> Print dialogue but all of a sudden it stopped working. I read somewhere that installing the latest version of Adobe Reader (version 11) would remove the old printer, so I did so. It took me about an hour on version 11 to even find the pdf print to file option, but I am getting the same message. For what it's worth, when I try print to file from Microsoft Word, I have no problem. I have no idea why things changed all of a sudden, but does anyone have any idea how I can get this working again?

    I checked with Adobe.  No luck. 
    Allow me to clarify my problem: 
    I have Adobe Reader XI. I also use a Mac--imac and a MacBook Pro.   My adobe was updated on 12/24.  Prior to that point, I could open my print dialogue box and there was a PDF tab on the bottom left.  In the drop down menu there were many choices, including but not limited to Open in PDF Preview, Print PDF, Save PDF, email PDF.  If I selected one page of 30 pages from a document saved in Adobe, I could extract just that one page and save it or email it, without having to send the entire document.   After the update, when I open a PDF file using ADOBE READER XI, and then open the print dialogue box, and follow those same steps, I get the message "Saving a PDF file when printing is not supported. Instead, choose File > Save."   My question is why is this feature now unavailable and is there a way to fix it? 
    The answer I got from Adobe was that Adobe never had this function, so it must have been via my print or preview programs..which are apple.  Does anyone have any thoughts?
    Thank you.
    https://forums.adobe.com/message/7124567 

Maybe you are looking for

  • Siri does not work on my iPad Air

    Siri is not responding on my ipad air

  • Any hope for wireless?

    I've recently moved on to a Mac Pro, but have kept my trusty G4 Laptop for traveling needs. It doesn't travel much, but when it does I'd like to be able to connect to available wireless networks. However, I never have equipped my G4 with an Airport c

  • IPod seen in "My Computer" but not iTunes

    I recently sent my laptop into repair after their was a fault my the HDD, I got the laptop back yesterday with everything wiped from it. I have redownloaded iTunes and pluged my iPod into the laptop via USB, however the iPod has not came up on the so

  • Item Category Determination during Sales Order Creation

    Dear All, This is Chee Wee, i'm new to SD, i would like to seek for an advice for the topic related to Item Category in Sales Order. We have a material "Mat005" define as "Stocked" Item category in MM03, *Stocked means our MM team will always keep st

  • The Dinosaur is Dieing, How to I get the files over Before it's Extinct?!?

    The hunk-o-junk is on it's death bed (YES!). Unfortunately: The computer freezes up every time we try to make backup CDs The computer is too old (MSFT WINDOWS 98) to send the stuff wirelessly. Don't think it has any ethernet connectivity We've got to