A couple small Applescript questions

Discussion in 'Mac Programming' started by iW00t, Jun 12, 2007.

  1. iW00t macrumors 68040

    iW00t

    Joined:
    Nov 7, 2006
    Location:
    Defenders of Apple Guild
    #1
    Hi,

    I really need to get an Applescript book at some point.

    How do I create a file in a particular folder (ie: ~/tmp) and then subsequently check the existence of said file and delete it if it is present?
     
  2. lancestraz macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #2
    Maybe this will help.

    Edit: Oh, you said "file". I though you said "folder". What kind of file?

    Code:
    set the_path to (path to desktop as string) -- Set the folder you want to create your folder in
    set folder_name to "test_folder" -- Give you new folder a name
    set the_folder to (the_path & folder_name & ":") -- Now combine the name and the path to make it easier to reference latter on
    
    tell application "Finder"
    	if (exists the_folder) is false then -- Check to see it the folder exists
    		make new folder at the_path with properties {name:folder_name}
    		delete the_folder
    	end if
    end tell
     
  3. iW00t thread starter macrumors 68040

    iW00t

    Joined:
    Nov 7, 2006
    Location:
    Defenders of Apple Guild
    #3
    It is just a dummy 0 byte file that is created by an earlier script to indicator that a process has taken place.

    Now here is for another really noobish question, how do you actually traverse through a list variable?
     
  4. lancestraz macrumors 6502a

    lancestraz

    Joined:
    Nov 27, 2005
    Location:
    RI
    #4
    Does this file have an extension?

    Like this.
    Code:
    set the_list to {"Item One", "Item Two", "Item Three"} -- Define your list
    
    repeat with i from 1 to number of items in the_list
    	set this_item to item i of the the_list -- Set "this_iten" to the next item in the list
    	display dialog this_item
    end repeat
     

Share This Page