Daily bothering with launchd and AppleScript 

Credit: All of the following “someone” is this one.

This morning I noticed this repo was forked into my GitHub organization. I’m still not sure what the original intent was but I interpreted as a permission/offer to contribute. Since the repo’s name is “simplifyLifeScripts”, I spent some time pondering upon what kind of scripts would simplify lives, or more specifically, my life. I then came up with this brilliant idea of automating iMessage sending so that my Mac can send someone this picture of Violet Evergarden on a daily basis:


In the past I had to do this manually by dragging the picture into the small iMessage text box, which was simply too painful to do (I blame Apple). How cool and fulfilling would it be to sit back and let the Apple’s product annoy an Apple employee!

After some GOOGLing I came across this snippet of AppleScript that lets you send an iMessage with your account:

on run {targetBuddyPhone, targetMessage}
    tell application "Messages"
        set targetService to 1st service whose service type = iMessage
        set targetBuddy to buddy targetBuddyPhone of targetService
        send targetMessage to targetBuddy
    end tell
end run

Basically it takes iMessage service from the system and tell it to send the message to a person given a phone number.

Since I also have to send an image as attachment, I added to this piece so it became:

on run {targetBuddyPhone, targetMessage, targetFile}
    tell application "Messages"
        set targetService to 1st service whose service type = iMessage
        set targetBuddy to buddy targetBuddyPhone of targetService

        set filenameLength to the length of targetFile
        if filenameLength > 0 then
            set attachment1 to (targetFile as POSIX file)
            send attachment1 to targetBuddy
        end if

        set messageLength to the length of targetMessage
        if messageLength > 0 then
            send targetMessage to targetBuddy
        end if
    end tell
end run

It now takes one more parameter that’s the file name. The script converts the file name to a POSIX file and send as attachment. I also added two simple checks so that I can send text and/or file.

The next step would be to automate the process. Just when I was ready to Google one more time someone pointed me to Apple’s launchd, which is similar to unix’s cron. launchd lets you daemonize pretty much any process. One needs to compose a plist (a special form of XML) file and put it under /Library/LaunchDaemons/, then the daemon would start as one of the system start up items.

Following the official guide, I made the following plist file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
        <string>Daily Lucy appreciation :p</string>

The ProgramArguments key is mapped to an array of arguments used to execute the process wrapped in the daemon. In my case, I just run osascript to execute the AppleScript at the absolute path, with the phone number, text message, and the image absolute path as parameters. The phone number is obviously censored.

The other key, StartCalendarInterval, is a handy way to run the job periodically. Any missing key will be filled with “*” wildcard. In this case, the process would be run every day at 00:00. I later changed it to 22:00 after realizing my computer might be shut down at midnight. Can’t miss the bother window.

To avoid restarting my laptop, after copying the file to the launchd directory I did sudo launchctl load {plist file path} so the daemon would start right away.

I did some testing with sending the message every minute and it worked perfectly. It’s worth noting that this is one of the few things that just worked the first try.

Excited for 10pm tonight! Although someone else might not be.

1,117 thoughts on “Daily bothering with launchd and AppleScript ”

  1. “A large percentage of of whatever you point out is supprisingly legitimate and that makes me ponder the reason why I hadn’t looked at this with this light before. Your article really did turn the light on for me personally as far as this specific subject matter goes. Nonetheless there is actually one particular issue I am not too comfy with so whilst I try to reconcile that with the central theme of your position, permit me see exactly what the rest of the visitors have to point out.Well done.”

  2. We’re several grouped volunteers plus starting off a fresh design in your local community. Your web blog provided us with beneficial facts for you to paintings about.. koleksi youtube terbaik You’ve got done the powerful career and also each of our entire area may be pleased for your requirements.

  3. After reading your post, you have a great website with interesting content. But I think you can improve your current google ranks by using SEO website traffic net. My friend uses it and it works great. Just google it, it’s very nice tool to bring you a lot of new readers on a daily basis. Keep up the quality work!

  4. Good day! I know this is kinda off topic but I was wondering if you knew where I could locate a
    captcha plugin for my comment form? I’m using the same
    blog platform as yours and I’m having difficulty finding one?
    Thanks a lot!

  5. I simply wanted to post a simple word in order to say thanks to you for some of the stunning concepts you are sharing on this website. My incredibly long internet look up has at the end been rewarded with really good facts and strategies to share with my companions. I would declare that we site visitors are truly endowed to live in a useful site with many marvellous professionals with interesting pointers. I feel rather lucky to have used your entire site and look forward to many more awesome minutes reading here. Thank you once again for all the details.

  6. Are you able to include a Blackberry mobile phones format? This specific website is difficult to learn Daily bothering with launchd and AppleScript  – Bill Yu in any other case for anyone folks browsing using mobile devices. In any other case, in the event you are listed a new Really simply syndication link up, that may be fantastic furthermore. Web Address http://feraripk.net/

  7. A lot of thanks for all of your labor on this website. My mum loves making time for investigations and it is easy to understand why. Most people know all concerning the compelling mode you render practical tips and tricks through your blog and as well as increase participation from some others on this content while our girl is always studying a great deal. Take pleasure in the remaining portion of the year. You’re doing a dazzling job.

  8. I and also my friends came reviewing the best helpful hints found on the website then immediately I got a terrible feeling I never expressed respect to the web site owner for those techniques. The young men are already for that reason passionate to learn all of them and have definitely been having fun with them. Many thanks for being considerably kind and for utilizing varieties of fabulous topics most people are really desperate to know about. My very own sincere apologies for not expressing appreciation to earlier.

  9. I must convey my passion for your kind-heartedness giving support to visitors who must have assistance with the subject. Your special dedication to passing the message all around came to be exceptionally beneficial and has surely helped somebody like me to realize their aims. The invaluable tutorial entails this much to me and somewhat more to my peers. Thank you; from everyone of us.

  10. I precisely wished to appreciate you all over again. I do not know what I would’ve accomplished without the actual advice discussed by you over that theme. Completely was an absolute hard crisis in my position, however , taking a look at your expert fashion you resolved the issue made me to weep with contentment. I’m happier for your guidance and in addition hope that you really know what an amazing job you happen to be carrying out instructing some other people using your blog post. Probably you haven’t got to know all of us.

  11. Thank you for your entire hard work on this blog. Ellie really likes engaging in investigation and it’s really easy to see why. All of us hear all of the dynamic way you offer priceless guides by means of the web blog and in addition welcome contribution from website visitors on the area then our girl is certainly studying so much. Enjoy the remaining portion of the year. Your doing a tremendous job.

  12. I enjoy you because of your whole hard work on this web site. My aunt really loves doing investigations and it’s really easy to see why. We hear all of the dynamic method you create both interesting and useful items by means of your web site and as well as improve response from other ones on this topic so our child has been learning so much. Take advantage of the rest of the year. Your carrying out a good job.

  13. Thank you for your whole work on this website. Gloria enjoys going through investigation and it’s easy to see why. Almost all hear all relating to the dynamic way you produce simple guidance on this blog and encourage response from other individuals on this area of interest then our own daughter is understanding a great deal. Enjoy the remaining portion of the year. You’re doing a first class job.

  14. I must show some thanks to you just for rescuing me from this type of scenario. Right after researching through the world-wide-web and getting tips which were not pleasant, I figured my entire life was over. Being alive without the presence of solutions to the issues you have fixed by way of your short post is a critical case, as well as the kind which could have badly damaged my entire career if I hadn’t discovered your blog. Your own natural talent and kindness in handling everything was very helpful. I am not sure what I would’ve done if I hadn’t encountered such a solution like this. I can also now relish my future. Thanks for your time so much for the impressive and result oriented help. I will not think twice to propose your blog post to any individual who would like direction about this matter.

  15. Thanks so much for providing individuals with an exceptionally remarkable opportunity to read critical reviews from this blog. It can be very amazing and as well , packed with a lot of fun for me and my office co-workers to visit the blog at least 3 times a week to read through the fresh guidance you have got. And lastly, I’m also certainly astounded for the striking strategies you give. Selected 2 points in this posting are really the very best I have ever had.

  16. I would like to voice my respect for your kind-heartedness for folks who need help with this important subject. Your special dedication to getting the solution across appears to be pretty important and has consistently encouraged workers like me to reach their desired goals. Your personal useful guide can mean a whole lot to me and especially to my office colleagues. Many thanks; from all of us.

  17. I want to get across my appreciation for your generosity supporting individuals that actually need help with this particular issue. Your very own dedication to getting the message all through turned out to be extremely functional and has constantly encouraged many people just like me to get to their desired goals. Your amazing warm and friendly recommendations can mean much a person like me and further more to my peers. Best wishes; from each one of us.

  18. Needed to compose you that bit of word in order to say thanks a lot over again about the unique ideas you have provided in this article. It was so tremendously open-handed with people like you to convey openly just what numerous people would have distributed as an electronic book in making some profit for their own end, primarily now that you could possibly have done it if you decided. Those techniques likewise worked like the fantastic way to be certain that many people have the same keenness like mine to understand whole lot more around this issue. I’m sure there are some more enjoyable situations ahead for people who looked at your website.

  19. I actually wanted to make a brief word to be able to appreciate you for those pleasant tricks you are showing on this website. My time consuming internet look up has at the end of the day been honored with awesome know-how to talk about with my pals. I would mention that we site visitors actually are undeniably blessed to dwell in a perfect network with very many outstanding individuals with insightful secrets. I feel extremely lucky to have used your entire website page and look forward to so many more fun minutes reading here. Thanks once more for all the details.

  20. My husband and i have been now relieved that Albert could finish off his investigations because of the ideas he received from your site. It is now and again perplexing to just be giving away ideas that some others might have been selling. And now we do know we’ve got the writer to thank for this. The main explanations you made, the straightforward site navigation, the relationships you will help promote – it’s got everything extraordinary, and it’s facilitating our son in addition to our family understand the content is enjoyable, which is certainly seriously vital. Thank you for the whole thing!

  21. I definitely wanted to develop a message to be able to appreciate you for all of the superb concepts you are posting on this website. My considerable internet investigation has at the end of the day been paid with high-quality points to share with my neighbours. I would assert that we visitors actually are very fortunate to exist in a fine site with so many brilliant professionals with interesting principles. I feel extremely privileged to have used your entire website page and look forward to some more fabulous minutes reading here. Thank you once more for a lot of things.

  22. I just wanted to write down a brief note so as to express gratitude to you for some of the nice strategies you are writing at this site. My prolonged internet lookup has at the end been recognized with excellent information to go over with my co-workers. I would assert that most of us visitors actually are undeniably fortunate to live in a remarkable site with many wonderful individuals with valuable tips and hints. I feel pretty grateful to have seen your entire webpages and look forward to some more fabulous moments reading here. Thank you once more for all the details.

  23. I precisely desired to thank you very much yet again. I do not know what I would’ve taken care of without those methods shared by you about that subject matter. Certainly was a real traumatic dilemma in my opinion, however , being able to view this skilled fashion you treated the issue forced me to cry over gladness. I am just happier for the guidance and expect you really know what an amazing job that you’re carrying out instructing other individuals all through your web page. I am sure you’ve never met all of us.

  24. My spouse and i have been really satisfied Edward managed to finish off his analysis while using the precious recommendations he received in your site. It’s not at all simplistic just to always be freely giving hints which usually many people could have been making money from. So we see we’ve got the writer to thank because of that. All the explanations you have made, the easy blog menu, the relationships you will give support to create – it is everything unbelievable, and it’s really assisting our son and us reason why that concept is brilliant, which is wonderfully vital. Thanks for all!

  25. I would like to show thanks to the writer for bailing me out of this dilemma. Right after browsing through the world-wide-web and obtaining basics which were not pleasant, I assumed my entire life was over. Being alive without the answers to the issues you have fixed as a result of your main site is a serious case, and the kind which may have in a negative way affected my entire career if I had not come across your web site. Your own personal talents and kindness in maneuvering every item was very useful. I’m not sure what I would have done if I had not discovered such a stuff like this. I can also at this point look forward to my future. Thanks a lot so much for your reliable and effective guide. I won’t hesitate to refer your web page to any person who needs tips on this matter.

  26. I am just commenting to make you know what a outstanding discovery our girl experienced reading your web site. She even learned a wide variety of details, most notably what it’s like to have an awesome teaching heart to make many people without difficulty master several tricky things. You really did more than her expected results. Many thanks for giving these warm and friendly, trusted, informative as well as cool thoughts on this topic to Tanya.

  27. I would like to show appreciation to this writer just for rescuing me from this particular dilemma. Because of looking out through the the net and coming across notions that were not pleasant, I figured my entire life was well over. Living devoid of the answers to the problems you’ve sorted out by way of this guide is a crucial case, and ones which might have adversely damaged my entire career if I hadn’t encountered the website. The training and kindness in playing with all the pieces was very helpful. I’m not sure what I would’ve done if I had not encountered such a solution like this. It’s possible to at this point look ahead to my future. Thanks for your time so much for this professional and effective guide. I won’t be reluctant to recommend your web site to anyone who needs and wants support about this matter.

  28. I simply wished to say thanks once again. I’m not certain what I would have handled in the absence of these secrets documented by you over such area of interest. It absolutely was a troublesome situation for me personally, but seeing this expert fashion you solved that forced me to jump with fulfillment. I am just thankful for your guidance and as well , believe you recognize what a great job you are accomplishing instructing most people by way of your site. More than likely you haven’t come across any of us.

  29. Youre so cool! I dont suppose Ive learn anything like this before. So nice to search out any person with some unique thoughts on this subject. realy thanks for starting this up. this web site is one thing that’s needed on the web, somebody with somewhat originality. useful job for bringing something new to the internet!

  30. I must express my gratitude for your kindness for those people who actually need assistance with this particular area of interest. Your special commitment to getting the solution throughout had become pretty practical and have continuously allowed associates much like me to reach their aims. This informative hints and tips denotes this much to me and even more to my fellow workers. Thanks a ton; from each one of us.

  31. I and my guys happened to be looking through the good pointers found on your web page and the sudden developed an awful feeling I never thanked you for those strategies. All of the ladies had been for that reason very interested to learn all of them and have in actuality been using these things. Appreciate your being quite considerate as well as for using varieties of superb guides most people are really desperate to be aware of. Our own honest regret for not expressing gratitude to you earlier.

  32. I precisely wished to say thanks yet again. I am not sure what I would have taken care of in the absence of those methods documented by you on this situation. It previously was an absolute depressing concern for me, but noticing this skilled avenue you managed that took me to jump for fulfillment. Now i’m grateful for your work and then trust you recognize what a powerful job you are always getting into training many people using your blog post. Probably you’ve never got to know any of us.

  33. 100有機潤唇膏 雙頭磨沙滋潤豐唇膏 滋潤豐唇蜜 亮彩保濕口紅 亮彩保濕唇蜜 持久亮麗雙頭唇彩 唇線筆 唇膏筆 抗炎作用原理:內環境平衡,增強陰道內免疫力 CO2可本質的改變組織特性,使粘膜組織新生 陰道上皮細胞功能增強,大量糖原在陰道桿菌作用下分解成乳酸,逐步恢復陰道正常的PH值 免疫力增強,降低私密處感染

  34. Howdy, i believe that we discovered anyone seen this blog page hence i got the following to return this want? . I’m seeking to to locate ebook trading saham troubles to boost this site! I guess it is good enough to make use of a a couple of your current methods!

  35. I spent four years trying EVERYTHING in Online Dating, and through a huge amount of trial and error, I produced a system that I will share for you. This book will take you, step by step, through everything you need to know to double, triple or even quadruple the number of women you meet online.

  36. 10招教你成為接吻高手 Marie Claire (HK) Edition 接吻是一件霸道的事,它會佔據人一瞬間全部注意力,令人當下只會專注投入唇舌間的互動。親吻可以讓情侶的愛意昇華,增進二人感情,前提是要吻得有技巧。別再讓糟糕的吻打破浪漫!經驗少也沒關係,只管留意以下一連串

  37. 高能聚焦量超聲波( HIFU )以物理性聚焦集中成一點, 快速穿透皮膚真皮及脂肪層面直達面部表淺肌肉腱膜系統( SMAS )層令其組織細胞分子高速磨擦 , 瞬間升溫至60 -70 度,令整個表淺肌肉腱膜系統( SMAS )受熱收縮,形成熱固化區域, 令結綈組織同時拉緊,達到拉皮防皺及美容效果。SMAZ聚焦超聲波提供了最有效的HIFU能量收緊皮膚及刺激胶原蛋白新生,提升彈性,恢復更緊緻的皮膚和更年輕的美貌。