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.

Similar Messages

  • Automator and applescript to copy new files in a folder with same name as parent folder

    I have an iMac with a pictures folder (Finder folder) containing several subfolders with pictures. As per now, all these subfolders are imported into an iPhoto library (and the structure of the Finder pictures folder is thus maintained: The iPhoto events are named the same as the Finder subfolder). I.e. I have not created any albums in iPhoto.
    I have also set up a workflow, where new iPhone photos are automatically being synced to specified Finder folders within the iMac pictures folder. So what I want to do is to make a workflow to import potential new photos from week to week into the existing iPhoto structure. I know iPhoto has this Autoimport folder, so this one is unpacked and "mapped". So, this is what I´m hoping to do:
    Automator (iCal - want to do this on a weekly basis):
    - Get specified Finder items -- set to target folder = iMac pictures folder
    - Get folder content (with subfolders)
    - Filter Finder items
         - Items from the last 7 days (which then would be any new files created last week)
    - Applescript/shell script loop(?)
         - Get folder name for each file´s (from previous step) parent folder
         - Create new folder with same name as the file´s parent folder (if not already existing) under the iPhoto Autoimport folder
         - Copy the given file into the folder from above
    - Run iPhoto application (Automator task), which then should just auto import the new photos according to the Finder folder structure
    Whith the workflow above, I aim to maintain the existing iPhoto structure, and just import new photos into the existing structure. Creating folder names under the Autoimport, similar as the existing Finder folder names / iPhoto events should make it possible to have the new files imported under the existing event, right?

    Anyone?
    I have now switched to Aperture (from iPhoto) due to Aperture´s capability to handle Finder folder structure, and due to the possibility of having the pictures within Aperture as referenced files to the pictures within the Finder folders (i.e. possibility to delete pictures from both library and Finder folder at the same time).
    So I have a superior Finder folder called "Album". Within "Album" I have several subfolders (sub albums) containing pictures. The "Album" folder with subfolders are imported into Aperture as "Projects and albums", and the pictures are uploaded within the Aperture structure as referenced files. So for now the Aperture structure is more or less a direct mirror of the Finder folder structure, whereas "Album" is the project.
    And this is my current workflow in Automator, but I´m searching help with my Applescript:
    - Get specified Finder items (target folder = the superior Finder folder "Album")
    - Get Folder content
    - Filter Finder items (to look for potential new files to import into Aperture)
         - Kind is not folder
         - Date created last X days
    The output files from this task enters an Applescript
    on run {input, parameters}
           repeat with f in input (**Loop**)
                   tell application "Finder"
                          set fileName to name of (f)
                          set parentFolder to name of container of (f)
                          tell application "Aperture"
                                 tell library 1
                                        tell project "Album"
                                               if (exists album parentFolder) then
                                                 ** I then would like to check if fileName already exist within the existing album**
                                                 ** If not existing, I would like to import file f into the existing album as a referenced file**              
                                               else if not (exists album parentFolder) then
                                                       make new album with properties {name:parentFolder}
                                                ** I then would like to import file f into the new album as a referenced file**
                                               end if
                                        end tell
                                 end tell
                          end tell
                   end tell
           end repeat
    end run

  • I'm trying to write an Applescript: when I add a file to a folder, I want finder to name it "1" and increment the other files in the folder by 1. i.e. once I drop a new file into the folder, the file originally called "1" will be renamed "2" etc

    I'm trying to write an Applescript. I have never used Applescript but my boss has just asked me to write a script so I dutifully nodded and said "Yes Boss"...
    The funtionality I need is that I want finder to rename the files in folder when I drop a new file in. When I add the new file (file neame: "1") to a folder, I want to increment the other file names in the folder by 1.
    So when I drop a my new "1" file into the folder, the file original file called "1" will be renamed "2", the original file named "2" will be renamed "3" etc
    I'm creating a 'stream' of images. When I add a new image i want it to nudge the other images in the folder along.
    Thanks guys!

    Maybe this will help. If you monitor the "More Like This" box (top right), other threads appear. Opening them usually displays other threads.
    https://discussions.apple.com/message/1986834#1986834

  • Creating AppleScript That Watches a Folder and Adds New Files to iTunes

    Is it possible to create a AppleScript that watches a folder and automatically adds any new files placed into the folder to my iTunes library?

    Probably. You can take a look through Doug's AppleScripts for iTunes and see if there's anything pre-existing you could use or modify.
    An alternative might be Hazel which says it can do that. It's not free, but if it works it would probably be a lot easier.
    Regards.

  • Applescript: Copy File Names into an Email

    *I've been slowly teaching myself Applescript, and can't seem to find a way to do a few things. Basically what I'm trying to do is set up a script that will run when items are dropped into a folder on my FTP. I want the script to have a pop-up dialogue, and generate an email to certain users announcing new files are on the FTP. I have these 2 parts down, but I would also like the body of the email to include a list of the filenames. This part I can't figure out.*
    *I just need to find a function that will copy the filenames of new items, and paste them into the body of the email already being generated. My current code is below. Anyone have any ideas to help me expand?*
    property dialog_timeout : 15 -- set the amount of time before dialogs auto-answer.
    on adding folder items to this_folder after receiving added_items
    try
    tell application "Mail"
    set theMessage to make new outgoing message with properties {visible:true, subject:"New Files on FTP", content:"New files have been posted to incoming folder of the FTP."}
    tell theMessage
    make new to recipient at end of to recipients with properties {name:"Jane Doe", address:"[email protected]"}
    make new to recipient at end of to recipients with properties {name:"John Smith", address:"[email protected]"}
    end tell
    send theMessage
    end tell
    tell application "Finder"
    --get the name of the folder
    set the folder_name to the name of this_folder
    end tell
    -- find out how many new items have been placed in the folder
    set the item_count to the number of items in the added_items
    --create the alert string
    set alert_message to ("Folder Actions Alert:" & return & return) as Unicode text
    if the item_count is greater than 1 then
    set alert_message to alert_message & (the item_count as text) & " new items have "
    else
    set alert_message to alert_message & "One new item has "
    end if
    set alert_message to alert_message & "been placed in folder " & «data utxt201C» & the folder_name & «data utxt201D» & "."
    set the alert_message to (the alert_message & return & return & "Would you like to view the added items?")
    display dialog the alert_message buttons {"Yes", "No"} default button 2 with icon 1 giving up after dialog_timeout
    set the user_choice to the button returned of the result
    if user_choice is "Yes" then
    tell application "Finder"
    --go to the desktop
    activate
    --open the folder
    open this_folder
    --select the items
    reveal the added_items
    end tell
    end if
    end try
    end adding folder items to
    Message was edited by: markeze

    AppleScript forum under OS X Technologies.

  • Folder Actions script no longer runs on new file creation

    Hope this isn't trivial.......first time posting here...hopefully in the right place.I'm not a total Mac OS X newbie...and surely no techie, either. Dabbled a wee bit with Automator and scratchin' my head on this one. Help, please!
    Any idea why folder actions not running when a new file is saved? A simple add-color-label script created in Automator was workin' fine before I did a Snow Leopard-to-Leopard downgrade clean-install & account migration from external HD (TimeMachine) backup. Folder actions are enabled and script runs only if I start it with Automator Runner. Previously, it would label the file as soon as I saved it....now it needs a manual start. Is this default behavior in Leopard? Or am I missing something or doin' something wrong? Or is this a consequence of downgrade? I was sure I had the same script workin ok in my original Leopard install - though possibly un-modified at that time.
    I have no clue why, but the new version I created recently (cpl wks ago?)worked the first time I added a new file but not thereafter...and in that instance it only labelled the file in Finder upon quitting Preview (file is a Grab saved as pdf).
    The reason for the downgrade was compatibility problems with Photoshop CS4 on SL (OS & app all updated yet crashin' at the drop of a hat) - maybe due to lack of RAM? (only 1GB). Saw quite a few posts regarding SL running CS4 problems, so now I'm back to running 10.5.8 ..again.. and PS actually runs smooth like it did before.
    Maybe these console messages are a help......or am I barkin' up the wrong tree?
    6/11/11 7:44:54 PM /System/Library/CoreServices/Folder Actions Dispatcher.app/Contents/MacOS/Folder Actions Dispatcher[91] CPSGetProcessInfo(): This call is deprecated and should not be called anymore.
    6/11/11 7:44:54 PM /System/Library/CoreServices/Folder Actions Dispatcher.app/Contents/MacOS/Folder Actions Dispatcher[91] CPSPBGetProcessInfo(): This call is deprecated and should not be called anymore.
    6/11/11 7:44:54 PM /System/Library/CoreServices/AppleScript Runner.app/Contents/MacOS/AppleScript Runner[264] CPSGetFrontProcess(): This call is deprecated and should not be called anymore. 
    6/11/11 8:19:12 PM Automator Runner[415] Error while processing arguments
    6/11/11 8:20:31 PM /Applications/AppleScript/Folder Actions Setup.app/Contents/MacOS/Folder Actions Setup[420] CPSGetProcessInfo(): This call is deprecated and should not be called anymore.
    6/11/11 8:20:31 PM /Applications/AppleScript/Folder Actions Setup.app/Contents/MacOS/Folder Actions Setup[420] CPSPBGetProcessInfo(): This call is deprecated and should not be called anymore.
    6/11/11 8:20:32 PM [0x0-0x5b05b].com.apple.systemevents[421] com.apple.FolderActions.enabled: Already loaded
    And for that matter....why does Automator throw these messages? All apps (except iWork '08 apps) and OS are up to date.
        - Just a few of the many actions not loaded:
    6/11/11 7:48:25 PM Automator[294] The action “Start iTunes Visuals” could not be loaded because the application “iTunes” is the wrong version.
    6/11/11 7:48:25 PM Automator[294] The action “Stop iTunes Visuals” could not be loaded because the application “iTunes” is the wrong version.
    6/11/11 7:48:25 PM Automator[294] The action “Update iPod” could not be loaded because the application “iTunes” is the wrong version.
    6/11/11 7:56:33 PM Automator[294] name = name was not found
    6/11/11 7:56:33 PM Automator[294] name = name extension was not found
    6/11/11 7:56:33 PM Automator[294] name = file type was not found
    6/11/11 8:00:29 PM Automator Runner[339] Error while processing arguments
    6/11/11 8:00:30 PM Automator Runner[339] The action “Import Files into iTunes” could not be loaded because the application “iTunes” is the wrong version.
    6/11/11 8:00:30 PM Automator Runner[339] The action “Add Songs to iPod” could not be loaded because the application “iTunes” is the wrong version.
    6/11/11 8:00:30 PM Automator Runner[339] The action “Add Songs to Playlist” could not be loaded because the application “iTunes” is the wrong version.
    6/11/11 8:00:30 PM Automator Runner[339] The action “Apply SQL” could not be loaded because the application “Xcode” was not found.
    Do I need to wipe the drive again and re-install everything?
    Any help is greatly appreciated. Apologies if this seems long-winded.

    Folder Actions are set up a bit differently in Leopard (they use an AppleScript wrapper), and several actions have been updated to use new technologies available in Snow Leopard.  Looking at some of your console logs, it looks like some actions or workflows were just copied over from Snow Leopard.  When changing versions like that, you should rebuild the workflows so that they link to the correct actions, and check added actions for any dependencies (an action won't be loaded if it requires resources that are not available).
    Resaving your Folder Action workflow as a Folder Action Plug-in should do the trick.

  • Can't create new file automator action

    I'm trying to create a new Automator action that prompts the user to choose a new file. The Action is similar to the "Ask for Finder Items" actions except that it asks the user to choose a new file and not one that already exists.
    I chose to write it in applescript:
    script PicknewFile
    property parent : class "AMBundleAction"
    on runWithInputfromAction_error(input, anAction, errorRef)
    return choose file with prompt "Where do you want to save it?"
    end runWithInputfromAction_error
    end script
    When I try and run it, I get the following error message in the Xcode console.
    [Switching to process 10606]
    Program received signal: “EXCBADACCESS”.
    [Switching to process 10606]
    sharedlibrary apply-load-rules all
    No memory available to program now: unsafe to call malloc
    Data Formatters temporarily unavailable, will re-try after a 'continue'. (Not safe to call dlopen at this time.)
    kill
    Does anybody know when this happens?
    Thanks,
    Scott

    Looks like I was wrong. I created a brand new project in Xcode and all I did as add "choose file name" to the applescript. It still gets a "EXCBADACCESS". I also tried a 'display dialog "Error"' in my applescript and it does the same thing.
    Here is the script the fails. Everything else in the project is default.
    script ChoosenewFile
    property parent : class "AMBundleAction"
    on runWithInputfromAction_error(input, anAction, errorRef)
    -- Add your code here, returning the data to be passed to the next action.
    display dialog "Error"
    return input
    end runWithInputfromAction_error
    end script
    In the debugger, this is the stack:
    #0 0x91184917 in objc_msgSend
    #1 0x63707472 in ??
    #2 0x16c01e36 in DecodeAEDescInternal
    #3 0x16c02b4b in DecodeObjectSpecifier
    #4 0x16c01c24 in DecodeAEDescInternal
    #5 0x16c022bb in DecodeAEList
    #6 0x16bccdd0 in ASExecuteEvent_PushSendStackFrame
    #7 0x16bccfcc in ASExecuteEvent
    #8 0x918026cb in callComponent_4444
    #9 0x16bc3d4a in AppleScriptComponent
    #10 0x917efcb6 in CallComponentDispatch
    #11 0x972455df in OSAExecuteEvent
    #12 0x00339ffe in +[BAObjectProto invokeScriptHandler:forObject:args:error:]
    #13 0x0033a363 in -[BAObjectProto invokeScriptHandler:args:error:]
    #14 0x0033b581 in -[BAObjectProto forwardInvocation:]
    #15 0x92f760c4 in __forwarding__
    #16 0x92f75bf2 in _forwarding_prep_0__
    #17 0x000718af in -[AMAction runWithInput:loopParent:]
    #18 0x00070d2f in -[AMWorkflowRunner runAction:withInput:loopParent:]
    #19 0x000c60a8 in -[AMWorkflowRunner runAction:]
    #20 0x0013261d in -[AMRunActionOperation main]
    #21 0x9094d34c in -[__NSOperationInternal start]
    #22 0x9094cfe0 in ___startOperations_block_invoke2
    #23 0x91caa7b8 in dispatch_call_block_andrelease
    #24 0x91c9c97e in dispatch_workerthread2
    #25 0x91c9c401 in pthreadwqthread
    #26 0x91c9c246 in start_wqthread
    Any more advice would be appreciated.
    Scott

  • Finder - Create new files directly from a folder using finder ?

    In Finder, is there a way to do a right-click in a folder and create a new file like: New Text File or New Document from that location?
    I used to do this oftenly in Windows (right click, New Word document) but I have not found it in Mac OS X, any work around ?
    Thanks

    Try the [Apple feedback page|http://www.apple.com/feedback>. However, note that this is unlikely to be added. It would be a very cumbersome feature.
    On Windows, you're almost guaranteed to be tied to a particular set of document creation tools. If you're using an office suite other than MS Office, you're so weird you might as well be using a Mac! This means that commands like "New Document" make sense there.
    On a Mac, a "document" could be created with MS Word, Pages, TextEdit, NeoOffice, OpenOffice, Mellel, Nisus Writer Marinter Write, or any of a host of other programs. (Mac users tend to put less emphasis on the popular tool and prefer to use the tool that "fits the hand" best.) Further complicating things is the fact that "document" is a very generic term, since every spreadsheet is a document, every Photoshop file is a document, etc. The contextual menu would rapidly become unmanageable if it had to fill up with "New Whatever Document" commands for every app on your hard drive!
    It is possible for you to add your own custom services to the contextual menu using AppleScript or Automator, and you should be able to create services to create new documents for the apps you use frequently. Check on the [AppleScript forum|http://discussions.apple.com/forum.jspa?forumID=724] for guidance on how to do this.

  • Keynote hyperlink to new file

    When a hyperlink is set to open a new file, is there a way to automatically close existing file when new one is opened?

    Welcome to the forums, ChrisEsch.
    Having no hands-off (or even cursorless) solution is a real problem. You might export just the music-laden presentation as a high-res full-screen QT movie, and embed that as a full-slide video on the first slide of the "second" presentation. Or, if the presentation will loop continuously, a better solution might be to export both the Keynote presentation and the soundtrack into iMovie, edit the video to the audio, and create a Quicktime movie.
    You might also be able to cobble something together in Applescript that automatically runs the second presentation when the first finishes, and keeps looping until stopped.
    As for the black between presentations, I'm not sure there's a good answer for that within Keynote, at least not one that isn't terribly cumbersome (such as running two copies of Keynote and switching between them again using Applescript). Again, exporting one of the presentations as a movie that runs on a single slide of the other would solve this.

  • Illustrator CC(2014) does not open or create new file in Window 8.1 Pro

    My illustrator can launch but once I tried to create a new file it would freeze and will not respond anymore.
    I also tried to open existing illustrator files it just create a blank white illustrator window and does not respond afterwards as well.
    I tried to reinstall the illustrator for times to fix to issue but it doesnt work.
    All the other applications (photoshop/indesign...) work perfectly, but obviously there is a bug in illustrator...
    Have any other people experienced similar issue and know how to fix it??

    Did you uninstall then used the Cleaner tool before reinstalling?
    Is a printer connected? Is the driver up to date? Printer turned on?
    Do you have any third party plugins installed?
    A graphic tablet?
    Any other hardware?
    Font management? Which one?
    Have you already tried setting up a new user account (Admin) and launching from that one?

  • Photoshop CS/CS2 in Macbook Pro cannont create new file or even open file!

    I got a Macbook Pro, updated all apple software to lastest version.
    Installed Photoshop CS as i did in PowerPC, and it cannont create a new file after finishing installation!. The Imageready is no problem but it cannot transfer the file to PS neither.
    the error message, "Photoshop cannot complete the required action DUE TO PROGRAM ERROR"
    I tried to installed the PS CS2, tryout. same problem!
    Please HELP!
    Macbook Pro 15"   Mac OS X (10.4.6)  

    Not sure what's happening there, but I've been running Photoshop CS2 on my MBP since the first week I had it. I updated to 10.4.6 and updated firmware today, and I just tried opening a file, and creating a new one, and it worked fine. Can you give a bit more information: for example, did you install from the original Photoshop CS2 disk?

  • Photoshop CC 2014.2.2 program error when I place a layer or open a new file

    I have just updated to the most recent PS CC2014 version. Twice, in fact, and the same problem persists. At some point while working on a file it will become impossible to place a new layer or open a new file. Other program functions work, but these will produce an error message: "Could not complete your request because of a program error." It's very frustrating and the only solution is to restart the program which will run fine for a while and then do it again.
    Is anyone else experiencing this? Or better still, has anyone found a solution to this issue?
    Richard

    I am experiencing a similiar problem.
    Ever since I upgraded to CC I have received this error after using Photoshop for more than 5 mins, or trying to performing tasks such as: placing a linked file, copying and pasting, dragging and dropping an image or even using "File>Open"
    I did a complete system clean install of Yosemite, and reinstalled CC completely 3 times.
    Any assistance in resolving would be greatly appreciated!
    Error Log Text:
    2015:01:06 13:41:33 : tracked key 0000000000001468 of type P5_ADsc not found : 1 : REQUIRE failed
    2015:01:06 13:41:33 : /Volumes/workarea/PS_15_Mac_Daily_Retail/20141204.r.310/photoshop/main/photoshop/xcode/.. /interfaces/UTrackResourceImp.h : 137 : REQUIRE failed
    2015:01:06 13:41:33 : tracked key 00000000000010C0 of type P5_ADsc not found : 1 : REQUIRE failed
    2015:01:06 13:41:33 : /Volumes/workarea/PS_15_Mac_Daily_Retail/20141204.r.310/photoshop/main/photoshop/xcode/.. /interfaces/UTrackResourceImp.h : 137 : REQUIRE failed
    2015:01:06 13:41:33 : tracked key 0000000000000E38 of type P5_ADsc not found : 1 : REQUIRE failed
    2015:01:06 13:41:33 : /Volumes/workarea/PS_15_Mac_Daily_Retail/20141204.r.310/photoshop/main/photoshop/xcode/.. /interfaces/UTrackResourceImp.h : 137 : REQUIRE failed
    2015:01:06 13:41:33 : tracked key 0000000000000460 of type P5_ADsc not found : 1 : REQUIRE failed
    2015:01:06 13:41:33 : /Volumes/workarea/PS_15_Mac_Daily_Retail/20141204.r.310/photoshop/main/photoshop/xcode/.. /interfaces/UTrackResourceImp.h : 137 : REQUIRE failed

  • Itunes saves my songs in a new file that is not the default setting

    My settings for downloading purchased music from itunes is c:\pop\music.
    Since a few months itunes generates a 2nd file named "music" within the existing file "music" and downloads all new songs in there. (It just happens, I surely didn´t tamper with the settings.)
    So everytime I buy music from the itunes store the new files are now saved under c:\pop\music\music.
    Also my ipod now only synchronizes the new files as long as they´re in c:\pop\music\music and not under c:\pop\music where I want to have them to be able to combine them with the others.
    I checked under "Information" of the new songs and for each song the setting for the place where it´s (supposed to be) saved under is still c:\pop\music. Also my default settings are still c:\pop\music.
    So why does itunes create a new file?????
    I can change almost every entry under "Information" but not the storage location.
    I don´t know why this happened and how I can change this back. Can anyone help me here, please!

    What im trying to say is, i purchased a imac after getting a new phone, which was on windows.
    So i now need to sync it so i can enjoy all the easy pleasures of genius so on and so on
    However not eveything made the shift over, so now my itunes on phone has songs from my old library, that due to whatever multiverse lays between mac and pc, are now not available on my new smarter and amazing mac.
    So if i sync the phone i will lose my songs, yes which did cost me money!! Does anyone know a way to prevent this?
    please bare in mind I am Mac simple, quite ******** really
    thank you in advance

  • Adding new files to the existing Keyword Collections

    Hi,
    I have been using Keyword Collections as folders when importing files - not sure if there is a "normal" way of creating folders for clips/audio/other files? 
    Anyway, when I start a project and import a folder with a few files, I create  Keyword Collection. Later on, when I add more files into that folder in Finder and try to import the same folder as keyword collection again, the "new" files will not be assigned with that keyword collection. They're thrown straight into the event and the keyword collection only shows files from the first import.
    In other words, having a Keyword Collection created when importing a folder - is there a way to assign more files to it later on? Sorry if it's a stupid question.
    Thanks,
    Kamil

    YYou can drag them into the keyword collection once you've imported them. Another simple way is to pick up the files in the Finder, use Cmd-tab to switch to FCP, and drag them directly to the collection. The clips will import using your import preference.

  • Action with new file with size from selection

    Hello,
    I try to record an action that takes a copy of the current image and creates a new file with the same dimensions. The action I record always has the file size of the new image hardcoded in it. I tried to set Preset to Clipboard, but this is not recorded in the action. This is with CS3.
    How can I create a new file that takes the current image size into account?
    Thanks for your help,
    Daniel

    You can record the menu 'Image-Duplicate' to make a copy of the whole image without recording the size. If the doc only has one layer you can also record the flyout menu of the layer's panel to duplicate the layer to a new document. The size will not be recorded.

Maybe you are looking for