{"id":10284,"date":"2018-12-12T10:19:49","date_gmt":"2018-12-12T15:19:49","guid":{"rendered":"http:\/\/blog.originlab.com\/?p=10284"},"modified":"2018-12-12T10:38:02","modified_gmt":"2018-12-12T15:38:02","slug":"how-to-run-origin-periodically","status":"publish","type":"post","link":"https:\/\/blog.originlab.com\/ja\/how-to-run-origin-periodically","title":{"rendered":"How to run Origin periodically using Windows Task Scheduler"},"content":{"rendered":"<p>You may wonder how to run the Origin application (data import, analysis, graphing, etc.) periodically, say at a certain time every day, or even only one specific time on a specific day. This blog explains the procedure to set up such task.\u00a0 Basically, you&#8217;ll need to program the sequence of the tasks, and use the Windows &#8220;<strong>Task Scheduler<\/strong>&#8221; to\u00a0 run a script file\u00a0 with a specific schedule.<\/p>\n<p>We will use the following example to illustrate:<\/p>\n<p><strong>1) Make a target process<\/strong><br \/>\nIn this sample, we will grab the latest update from <a href=\"https:\/\/www.swpc.noaa.gov\/products\/3-day-forecast\">an NOAA page<\/a> and generate a graph and export it as image file to rour desktop. The OriginC code is as below (you can also directly <a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/12\/NOAAProcessCode.zip\">download this file<\/a> and put the file under your &lt;User Files Folder&gt;\\OriginC)<\/p>\n<pre class=\"toolbar:0 popup:false scroll:true minimize:true lang:c++ decode:true \">void ProcessTest_NOAA() {\r\n\tstring strURL = \"http:\/\/services.swpc.noaa.gov\/text\/3-day-forecast.txt\";\r\n\tstring strFile = GetOriginPath(ORIGIN_PATH_USER) + \"NOAA.txt\";\r\n\tint err = okutil_http_download(strURL, strFile);\r\n\tif (err == 0) {\r\n\t\tWorksheet wks;\r\n\t\twks = ImportNOAAFile(strFile);\r\n\t\tDeleteFile(strFile);\r\n\t\tif (wks.IsValid()) {;\r\n\t\t\tExportGraph(MakeGraph(wks));\r\n\t\t}\r\n\t}\r\n\tProject.ClearModified();\r\n\tLT_execute(\"exit;\")\r\n}\r\n\r\nstatic Worksheet ImportNOAAFile(string strFullPath) {\r\n\tWorksheet wks;\r\n\tASCIMP  ai;\r\n    if(AscImpReadFileStruct(strFullPath, &amp;ai)==0) {\r\n    \tai.iDelimited = 0;\r\n\t    strcpy(ai.szFixedWidth,\"10, 11, 11, 11\");\r\n       \tai.iHeaderLines = 13;\r\n\t    ai.iSubHeaderLines = 1;\r\n\t\tai.iAutoSubHeaderLines = 0;\r\n\t\tai.iRenameWks = 0;\r\n\t\tai.nLongNames = 0;\r\n\t\tai.iPartial = 1;\r\n\t\tai.iPartialR1 = 0;\r\n\t\tai.iPartialR2 = 8;\r\n\t\tai.iPartialC1 = 0;\r\n\t\tai.iPartialC2 = 3;\r\n\t\t\r\n\t\twks = Project.ActiveLayer();\r\n\t\twks.SetSize(-1, 5);\r\n\t\tDataset ds;\r\n\t\tif (0 == wks.ImportASCII(strFullPath, ai)) {\r\n\t\t\t\/\/ Time\r\n\t\t\tds.Attach(wks, 0);\r\n\t\t\tds = UnwrapTime(wks.Columns(0), GetToday());\r\n\t\t\twks.Columns(0).SetLongName(\"Time\");\r\n\t\t\twks.Columns(0).SetUnits(\"UT\");\r\n\t\t\twks.Columns(0).SetFormat(OKCOLTYPE_DATE); \r\n\t\t\twks.Columns(0).SetSubFormat(9); \r\n\t\t\t\r\n\t\t\t\/\/ Data\r\n\t\t\tds.Attach(wks, 4);\r\n\t\t\tds.SetSize(0);\r\n\t\t\tfor(int ii = 1; ii &lt;= 3; ii++) {\r\n\t\t\t\tvector&lt;double&gt; vs;\r\n\t\t\t\tvs = UnwrapData(wks.Columns(1));\r\n\t\t\t\tds.Append(vs);\r\n\t\t\t\twks.DeleteCol(1);\r\n\t\t\t}\r\n\t\t\twks.Columns(1).SetLongName(\"Kp index\");\r\n\t\t}\r\n    }\r\n    return wks;\r\n}\r\n\r\nstatic vector&lt;double&gt; UnwrapTime(const Column &amp;cc, double dToday) {\r\n\tvector&lt;double&gt; vs;\r\n\tvector&lt;string&gt; sa;\r\n\tcc.GetStringArray(sa);\r\n\tvs.SetSize(sa.GetSize()*2*3);\r\n\tfor(int nDayOffset = 0; nDayOffset &lt;=2; nDayOffset++) {\r\n\t\tfor(int ii = 0; ii &lt; sa.GetSize(); ii++) {\r\n\t\t\tvs[ii*2+nDayOffset*sa.GetSize()*2] = (int)dToday + nDayOffset + atof(sa[ii].Mid(0, 2))\/24;\r\n\t\t\tvs[ii*2+1+nDayOffset*sa.GetSize()*2] = (int)dToday + nDayOffset + atof(sa[ii].Mid(3, 2))\/24;\r\n\t\t\tif (ii == sa.GetSize()-1) {\r\n\t\t\t\tvs[ii*2+1+nDayOffset*sa.GetSize()*2] = (int)dToday + nDayOffset + 1;\r\n\t\t\t}\r\n\t\t}\r\n\t}\r\n\t\r\n\treturn vs;\r\n}\r\n\r\nstatic vector&lt;double&gt; UnwrapData(const Column &amp;cc) {\r\n\tvector&lt;double&gt; vs;\r\n\tvector&lt;string&gt; sa;\r\n\tcc.GetStringArray(sa);\r\n\tvs.SetSize(sa.GetSize()*2);\r\n\tfor(int ii = 0; ii &lt; sa.GetSize(); ii++) {\r\n\t\tvs[ii*2] = vs[ii*2+1] = ChkDataValue(sa[ii]);\r\n\t}\r\n\t\r\n\treturn vs;\r\n}\r\n\r\nstatic double ChkDataValue(string str) {\r\n\tif (is_missing_value(atof(str))) {\r\n\t\tstr.TrimLeft();\r\n\t\tstr.TrimRight();\r\n\t\treturn atof(str.Left(str.Find('(')));\r\n\t}\r\n\telse {\r\n\t\treturn atof(str);\r\n\t}\r\n}\r\n\r\nstatic double GetToday() {\r\n\tSYSTEMTIME sysTime;\r\n\tGetSystemTime(&amp;sysTime);\r\n\tdouble dDate;\r\n\tSystemTimeToJulianDate(&amp;dDate, &amp;sysTime);\r\n\treturn dDate;\r\n}\r\n\r\nstatic GraphPage MakeGraph(const Worksheet &amp;wks) {\r\n\tCurve cv(wks, 0, 1);\r\n\tGraphPage gp;\r\n\tgp.Create(\"Origin\");\r\n\tGraphLayer gl = gp.Layers(0);\r\n\tDataPlot dp = gl.DataPlots(gl.AddPlot(cv, IDM_PLOT_LINE));\r\n\tgl.GraphObjects(\"Legend\").Destroy();\r\n\t\r\n\tTree tr;\r\n\ttr = dp.GetFormat(FPB_ALL, FOB_ALL, true, true);\r\n\ttr.Root.Line.Color.nVal = 20724986;\t\/\/ red\r\n\ttr.Root.Line.Connect.nVal = 4;\t\/\/B-Spline\r\n\ttr.Root.Line.Width.dVal = 2;\r\n\tdp.ApplyFormat(tr, true, true); \r\n\t\r\n\tgl.XAxis.Scale.IncrementBy.nVal = 0;\r\n\tgl.XAxis.Scale.Value.dVal = 1;\r\n\tgl.XAxis.Scale.RescaleMargin.dVal = 0;\r\n\ttr = gl.XAxis.GetFormat(FPB_ALL, FOB_ALL, true, true);\r\n\ttr.Root.Labels.BottomLabels.Type.nVal = 3;\r\n\ttr.Root.Labels.BottomLabels.DateFormat.nVal = 2;\r\n\tgl.XAxis.ApplyFormat(tr, true, true); \r\n\tgl.Rescale();\r\n\tgp.LT_execute(\"page.aa=1;\");\r\n\t\r\n\treturn gp;\r\n}\r\n\r\nstatic void ExportGraph(const GraphPage &amp;gp) {\r\n\tstring strGraphType = \"png\";  \r\n\tstring strFileName = get_date_str(GetToday(), LDF_ALPHAMONTH_NUMERICDAY) + \"~\" + get_date_str(GetToday()+2, LDF_ALPHAMONTH_NUMERICDAY);\r\n\tstring strGraphPath = okutil_get_origin_path(ORIGIN_PATH_USER_APPDATA);\t\r\n\tstrGraphPath = strGraphPath.Left(strGraphPath.Find(\"AppData\")) + \"Desktop\\\\\";\r\n\tstrGraphPath += strFileName + \".\" + strGraphType;\r\n\texport_page(gp, strGraphPath, strGraphType);  \r\n}<\/pre>\n<p>The LabTalk script to call the Origin C function is straight forward:<\/p>\n<pre class=\"lang:default decode:true\">[Main]\r\nrun.loadoc(&lt;FileName&gt;, 16);\r\nProcessTest_NOAA();\r\n<\/pre>\n<p>Save this script to a file, say, <strong>ScheduledTask.OGS<\/strong> in your User Files Folder (UFF).<\/p>\n<p><strong>2) Start the Task Scheduler<\/strong><br \/>\nRun the Window &#8220;<strong>Task Scheduler<\/strong>&#8220;. You can find this tool in the <strong>Control Panel<\/strong>:<br \/>\n<em><strong>Control Panel&gt; System and Security&gt; Administrative Tools&gt; Task Scheduler\u00a0 \u00a0 \u00a0<\/strong><\/em><em><strong><br \/>\n<\/strong><\/em><\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8540 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-1.jpg\" alt=\"\" width=\"800\" height=\"572\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-1.jpg 800w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-1-300x215.jpg 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-1-768x549.jpg 768w\" sizes=\"auto, (max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n<p><strong>3) Create a Basic Task<\/strong><br \/>\nSelect <strong>&#8220;Create Basic Task&#8230;&#8221;<\/strong> in the right side panel. You move to the &#8220;<strong>Create Basic Task<\/strong>&#8221; page. Here, enter your task&#8217;s name and the description like the screenshot below. Press &#8220;<strong>Next<\/strong>&#8220;. (You move to the &#8220;Task Trigger&#8221; page.)<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8542 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-2.jpg\" alt=\"\" width=\"705\" height=\"495\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-2.jpg 705w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-2-300x211.jpg 300w\" sizes=\"auto, (max-width: 705px) 100vw, 705px\" \/><\/a><\/p>\n<p><strong>4) Set the Type of Schedule<\/strong><br \/>\nIn the &#8220;<strong>Task Trigger<\/strong>&#8221; page, choose the type of event such as <strong>Daily<\/strong>, <strong>One Time<\/strong>, etc. Press &#8220;<strong>Next<\/strong>&#8220;. (You move to the type specific page like &#8220;Daily&#8221;.)<a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8543 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-3.jpg\" alt=\"\" width=\"710\" height=\"494\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-3.jpg 710w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-3-300x209.jpg 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-3-135x93.jpg 135w\" sizes=\"auto, (max-width: 710px) 100vw, 710px\" \/><\/a><br \/>\n<strong>5) Set the Date and Time to Run<\/strong><br \/>\nIn the task specific page, set the date\/time for the event. In this sample, we set it as\u00a0<strong>8:00 AM everyday<\/strong>. Press &#8220;<strong>Next<\/strong>&#8220;. (You move to the &#8220;Action&#8221; page.)<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8544 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-4.jpg\" alt=\"\" width=\"713\" height=\"497\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-4.jpg 713w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-4-300x209.jpg 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-4-135x93.jpg 135w\" sizes=\"auto, (max-width: 713px) 100vw, 713px\" \/><\/a><br \/>\n<strong>6) Select &#8220;Start a Program&#8221; as an Action<\/strong><br \/>\nIn the &#8220;<strong>Action<\/strong>&#8221; page, choose &#8220;<strong>Start a program<\/strong>&#8220;, and press &#8220;<strong>Next<\/strong>&#8220;. (You move to the &#8220;Start a Program&#8221; page.)<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-5.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8545 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-5.jpg\" alt=\"\" width=\"712\" height=\"497\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-5.jpg 712w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-5-300x209.jpg 300w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-5-135x93.jpg 135w\" sizes=\"auto, (max-width: 712px) 100vw, 712px\" \/><\/a><\/p>\n<p><strong>7) Set the Origin Program and the LabTalk Script to Run<\/strong><br \/>\nIn the &#8220;<strong>Start a Program<\/strong>&#8221; page, in the &#8220;Program\/script:&#8221; field, enter the command line to call Origin to run the specific LabTalk script file. In our case, we enter:<\/p>\n<pre class=\"lang:default decode:true\">\"C:\\Program Files\\OriginLab\\Origin2019\\Origin96_64.exe\" -rs run.section(ScheduledTask.OGS,main)<\/pre>\n<p>Here, <strong><em>C:\\Program Files\\OriginLab\\Origin2019\\<\/em><\/strong> is the program folder path where Origin is installed. Your path may be different.\u00a0 To check your path, choose &#8220;<strong>Help: Open Folder: Program Folder<\/strong>&#8221; menu.\u00a0\u00a0<strong><em>Origin96_64.exe<\/em><\/strong> is the Origin executable program name. Note that different versions of Origin will have a different names, so you need to update this baed on your installed version.\u00a0\u00a0<strong><em>ScheduledTask.OGS<\/em><\/strong> is the name of the LabTalk script file, and <strong><em>main<\/em> <\/strong>is the script section name to run, which is the first line in the script file, that is &#8220;<strong>[Main]<\/strong>&#8220;.<br \/>\nPress &#8220;<strong>Next<\/strong>&#8220;. (A prompt would appear, and you click Yes. You move to the &#8220;<strong>Summary<\/strong>&#8221; page.)<\/p>\n<p><strong>8) Check and Complete<\/strong><br \/>\nIn the &#8220;<strong>Summary<\/strong>&#8221; page, check your input information, and if correct, press &#8220;<strong>Finish<\/strong>&#8221; button.\u00a0 Otherwise, you can go back to previous pages by pressing &#8220;<strong>&lt;Back<\/strong>&#8221; button.<\/p>\n<p><a href=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/scr_TaskScheduler-8.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter wp-image-8555 size-full\" src=\"http:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/Task_Schedule_Finish.png\" alt=\"\" width=\"697\" height=\"488\" srcset=\"https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/Task_Schedule_Finish.png 697w, https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/01\/Task_Schedule_Finish-300x210.png 300w\" sizes=\"auto, (max-width: 697px) 100vw, 697px\" \/><\/a><\/p>\n<p>Now your task is all set to run as scheduled!<\/p>\n<p><strong><br \/>\nNote:<\/strong> If you want to run the task several times in a day, create multiple tasks.<strong><br \/>\n<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>You may wonder how to run the Origin application (data &hellip; <\/p>","protected":false},"author":14,"featured_media":10288,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2},"jetpack_post_was_ever_published":false},"categories":[5,12,3,99],"tags":[],"class_list":["post-10284","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming-oc","category-data-import","category-data-handling","category-batch-processing"],"jetpack_publicize_connections":[],"jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p7DvU2-2FS","jetpack_likes_enabled":true,"jetpack_featured_media_url":"https:\/\/blog.originlab.com\/wp-content\/uploads\/2018\/12\/Scheduled-Tasks-Icon.png","post_mailing_queue_ids":[],"_links":{"self":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts\/10284","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/users\/14"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/comments?post=10284"}],"version-history":[{"count":3,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts\/10284\/revisions"}],"predecessor-version":[{"id":10308,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/posts\/10284\/revisions\/10308"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/media\/10288"}],"wp:attachment":[{"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/media?parent=10284"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/categories?post=10284"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.originlab.com\/ja\/wp-json\/wp\/v2\/tags?post=10284"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}