Ask Different is a question and answer site for power users of Apple hardware and software. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I tried to do this with Automator and found it...lacking. I have tried to look for solutions everywhere else I can think of, but my searches keep pointing me to Applescript as the only available answer.

I need to automate this daily task that's very time consuming and have no idea how to do it in Applescript since I only started "learning" about it two days ago.

Hopefully someone here can help me out.

Here's what I want to do:

  1. I have a master list of domains.
  2. Compare the secondary list of domains I create everyday and have the duplicate entries removed (duplicates when compared to the master list).
  3. Then after I have had a chance to copy the left-over (non-duplicate) domains, have them be added to the master list for tomorrow.

It seems simple enough for this non-programming mind of mine, but I can't seem to find an easy way of doing this anywhere.

If you can think of an easy way that I'm not thinking of, please do let me know. Or if you have that gifted touch with Applescript, please tell me how to do this.

Thank you kindly in advance.


share|improve this question
Do you need to specifically know the domains added every day or do you need just the updated list without duplicates at the end? – patrix Feb 27 '13 at 10:01

It would be easier to use shell scripting:

grep -vxf master.txt today.txt > today2.txt; cat master.txt today2.txt > master2.txt

share|improve this answer
How do I do that??? Terminal? Sorry, I'm a tech-challenged. – Thomas Feb 25 '13 at 17:11
Yes, open a Terminal and go to the folder where the files are located (with cd foldername (assumes the folder is in your home directory). Then copy and paste Lauri's command into the terminal and press Enter. If you were going do to this often, you'd write a shell-script file with that command (the details of doing that are a bit beyond a comment in this thread). – JRobert Feb 25 '13 at 18:01

If you're more comfortable with Applescript you can run the shell script of @Lauri Ranta with the following AppleScript :

do shell script "grep -vxf master.txt today.txt > today2.txt; cat master.txt today2.txt > master2.txt"

If this isn't clear for you, I've done an AppleScript including the shell script of @Lauri Ranta.

Here's how to step by step build an AppleScript application that will merge today list to a master list without duplicates
. Paths to master & today lists are saved between launchs or asked if not found/defined
. After merge, today list is cleared

1. Open AppleScript Editor

2. Paste following code

-- Merge today list to a master list without duplicates
-- . Paths to master & today lists are saved between launchs or asked if not found/defined
-- . After merge, today list is cleared

-- Path to temporary items folder
property pathToTemp : POSIX path of (path to temporary items)

-- Paths to temporary files
property newAdds_temp : pathToTemp & "mergeLists_new_adds.tmp"
property mergedList_temp : pathToTemp & "mergeLists_merged_list.tmp"

-- Paths to lists
property masterFile : ""
property todayFile : ""

if (masterFile is "") or (not FileExists(masterFile)) then
    set todayFile to ""
    set masterFile to choose file with prompt "Select the master list :"
end if
if (masterFile is false) then
    set todayFile to ""
    set masterFile to ""
    if (todayFile is "") or (not FileExists(todayFile)) then
        set todayFile to choose file with prompt "Select the list to add :"
    end if
    if (todayFile is not false) then

        -- Prepare the shell script :       
        set masterFile_posix to POSIX path of masterFile
        set todayFile_posix to POSIX path of todayFile
        -- . Save new adds to newAdds_temp
        set shellScript to "grep -vxf " & masterFile_posix & " " & todayFile_posix & " > " & newAdds_temp & "; "
        -- . Merge master list & new adds to mergedList_temp (and remove newAdds_temp file)
        set shellScript to shellScript & "cat " & masterFile_posix & " " & newAdds_temp & " > " & mergedList_temp & "; unlink " & newAdds_temp & "; "
        -- . Replace master list by merged mergedList_temp
        set shellScript to shellScript & "mv -f " & mergedList_temp & " " & masterFile_posix & "; "
        -- . And clean today file
        set shellScript to shellScript & "echo \"\" > " & todayFile_posix

        -- Execute the generated shell script
        do shell script shellScript

        -- And display a message
        display dialog "Merge done."
    end if
end if

-- This function is inspired from Philip Regan answer on :
on FileExists(theFile)
    tell application "System Events" to return (exists theFile)
end FileExists

3. Export as an application

File menu > Export > FileFormat : Application

4. Backup your lists !

5. Try the application you just created

share|improve this answer
Thank you Lauri, JRobert, and Bibou for your help. – Thomas Feb 26 '13 at 12:54
Bibou, I have run the script you gave me and works like a charm. I don't have any idea running shell script (and couldn't get it to work) so the applescript is a great relief (at least I know how to copy and paste and compile for that). Thank you so much for your help everyone! – Thomas Feb 26 '13 at 13:00
Ran into a problem here... I tested the script with "master" and "today" file names. I have now tried to re-run with actual file names and the script keeps adding a blank file called "today". After failing to remedy the best I could with my limited knowledge, I tried to just past today's info in the script-created "today" file and ran it again. The "today" is cleaned up as supposed to, but the "master" hasn't copied the info over and remains static. Help!?!? – Thomas Feb 27 '13 at 3:05
Hi Thomas, I think the problem comes from my script that didn't forgive old paths. I have edited my code to : forget today file path if master changed. Make a new app with this code, it should ask for your master & today files. If you want to redefine today & master path, the master should not be found, move/rename it, launch the app & it will ask for new paths. The previous version can forget old paths if both master & today's files (as defined for the app) are not found at start of the app. – Bibou Feb 27 '13 at 9:54
Thanks so much again Bibou. Appreciate it greatly. If a newbie like myself wanted to start learning a programming language, would you recommend I start with Applescript or shell? Which is easier to learn AND has more possibilities of being useful? – Thomas Feb 28 '13 at 3:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.