How to save the list as txt file?

Discussion in 'Mac Programming' started by chidambaram, Mar 10, 2009.

  1. macrumors member

    Joined:
    Mar 9, 2008
    #1
    Hi all,

    I want to save the list of applications in my machine in a text file.

    In terminal i did as "cd /Applications" and in next line "ls" . I received all the applications in my machine.

    How can i save this list in text file using applescript.

    Thanks in advance...
     
  2. macrumors member

    Joined:
    Jul 3, 2003
    Location:
    London
    #2
    I don't know about Applescript, but you can simply do this to save the list in a text file:

    cd /Applications
    ls > file.txt

    If you specifically need Applescript I hope someone else can help you :)
     
  3. macrumors member

    Joined:
    Aug 5, 2003
    Location:
    Scheßlitz, Oberfranken, Bavaria, Germany
    #3
    Hi,
    instead of just "ls" do "ls > allPrgs.txt"

    Best regards
    Peter
     
  4. thread starter macrumors member

    Joined:
    Mar 9, 2008
    #4
    thanks for all replies...

    its working fine in terminal.

    But i need in applescript...
     
  5. macrumors 6502

    Joined:
    Mar 9, 2005
    Location:
    Malta
    #5
    not sure if i am understanding this right, but maybe i can help you...

    Try to select all the applications and copy them. then open up textedit and paste and match style (do not paste as it wont work and will quit textedit). You will have a list of the applications you have copied...

    hope it helps you
     
  6. thread starter macrumors member

    Joined:
    Mar 9, 2008
    #6
    I get the list of applications. I want to save that my code is

    tell application "TextEdit"
    activate
    make new application
    tell application "Terminal"
    do script "cd /Applications"
    do script "ls" in window 1
    end tell
    end tell


    how can i save the result coming in ls command in text file?
     
  7. macrumors 6502a

    Joined:
    Mar 19, 2008
    Location:
    North Shore, MA
    #7
    What sort of information do you need? Using the below command may be a bit more thorough:
    Code:
    /usr/sbin/system_profiler SPApplicationsDataType
     
  8. Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #8
    Here's simplified AppleScript. You don't need all those tell applications. It'll ask for a name of the file with a prompt, then use it in the output command. If it'll be a fixed name for the output you can skip the prompt and tie it in directly to the cmd. It's also currently set to save the file to your home directory.

    Code:
    display dialog "Enter name of file to be saved" default answer ""
    set dialogInfo to result
    set filename to text returned of dialogInfo
    -- create command for script
    set cmd to "ls /Applications/ > ~/" & filename
    do shell script cmd
     

Share This Page