diff --git a/.gitignore b/.gitignore index b2f98577..a2603413 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ /src/tagui_service.done # exclude local files for chrome integration +/src/chrome/tagui_user_profile /src/tagui_chrome.in /src/tagui_chrome.out /src/tagui_chrome.log diff --git a/README.md b/README.md index f6054de3..5c0f32c2 100755 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ ***TagUI is now maintained by [AI Singapore (aisingapore.org)](https://www.aisingapore.org), a government-funded initiative to build local artificial intelligence capabilities. The intention is to add AI capabilities to TagUI while keeping it open-source and free to use. To get started, check out above hands-on tutorial, Prezi slides, or recorded video at FOSSASIA 2018.*** ### FEATURES -***TagUI is a RPA / CLI tool for digital process automation*** +***TagUI is a CLI tool for digital process automation (RPA)*** - automate Chrome visibly or headlessly - visual automation of websites and desktop - write in 20+ human languages & JavaScript diff --git a/src/tagui b/src/tagui index 47d0542d..50c97786 100755 --- a/src/tagui +++ b/src/tagui @@ -224,8 +224,6 @@ tagui_data_set_size=1 if [ -f "$1".csv ]; then min_column=`awk -F',' '{print NF}' "$1".csv | sort -nu | head -n 1` max_column=`awk -F',' '{print NF}' "$1".csv | sort -nu | tail -n 1` -# comment off sanity check for columns consistency as cells with , will trigger false-positive -# if [ "$min_column" != "$max_column" ]; then echo "ERROR - $1.csv has inconsistent # of columns" | tee -a "$1".log if [ "$min_column" -lt 2 ]; then echo "ERROR - $1.csv has lesser than 2 columns" | tee -a "$1".log else tagui_data_set_size="$(($min_column-1))"; fi; fi @@ -273,17 +271,21 @@ headless_switch=""; if [ "$tagui_web_browser" == "headless" ]; then headless_swi if [ "$tagui_data_set" -eq 1 ] || [ "$tagui_speed_mode" == false ]; then # check for which operating system and launch chrome accordingly -chrome_started="$(uname -s)"; chrome_switches="--remote-debugging-port=9222 about:blank" +chrome_started="$(uname -s)"; chrome_switches="--user-data-dir=chrome/tagui_user_profile --remote-debugging-port=9222 about:blank" if [ "$chrome_started" == "Darwin" ]; then if ! [ -f "/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ]; then echo "ERROR - cannot find Chrome at \"/Applications/Google Chrome.app/Contents/MacOS/Google Chrome\"" echo "Chrome is at a non-standard location on your macOS, raise an issue on TagUI GitHub page"; exit 1; fi -pkill Google\ Chrome; /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $chrome_switches $window_size $headless_switch > /dev/null 2>&1 & +chrome_process_id="$(ps | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" +if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi +/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $chrome_switches $window_size $headless_switch > /dev/null 2>&1 & else if ! type "$chrome_command" > /dev/null; then echo "ERROR - cannot find Chrome command \"$chrome_command\"" echo "update chrome_command setting in tagui/src/tagui and make sure symlink to command is created"; exit 1; fi -pkill $chrome_command; $chrome_command $chrome_switches $window_size $headless_switch > /dev/null 2>&1 & +chrome_process_id="$(ps | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" +if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi +$chrome_command $chrome_switches $window_size $headless_switch > /dev/null 2>&1 & fi # wait until chrome is ready with websocket url for php thread @@ -310,8 +312,13 @@ if [ -f "tagui.sikuli/tagui_sikuli.in" ]; then echo "finish" > tagui.sikuli/tagu if [ -f "tagui_chrome.in" ]; then echo "finish" > tagui_chrome.in; fi # kill chrome processes by checking which os the processes are started on -if [ "$chrome_started" == "Darwin" ] && [ "$tagui_speed_mode" == false ]; then pkill Google\ Chrome -else if [ -n "$chrome_started" ] && [ "$tagui_speed_mode" == false ]; then pkill $chrome_command; fi; fi +if [ "$chrome_started" == "Darwin" ] && [ "$tagui_speed_mode" == false ]; then +chrome_process_id="$(ps | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" +if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi +else if [ -n "$chrome_started" ] && [ "$tagui_speed_mode" == false ]; then +chrome_process_id="$(ps | grep remote-debugging-port=9222 | grep tagui_user_profile | sed -e 's/^[ ]*//' | cut -d' ' -f 1 | sort -nur | head -n 1)" +if [ -n "$chrome_process_id" ]; then kill $chrome_process_id; fi +fi; fi # end of big loop for managing multiple data sets in datatable done diff --git a/src/tagui.cmd b/src/tagui.cmd index 791fc732..3a26c9c4 100644 --- a/src/tagui.cmd +++ b/src/tagui.cmd @@ -482,10 +482,6 @@ if not exist "%flow_file%.csv" goto no_datatable for /f "tokens=* usebackq" %%c in (`gawk -F"," "{print NF}" "%flow_file%.csv" ^| sort -nu ^| head -n 1`) do set min_column=%%c for /f "tokens=* usebackq" %%c in (`gawk -F"," "{print NF}" "%flow_file%.csv" ^| sort -nu ^| tail -n 1`) do set max_column=%%c -rem comment off sanity check for columns consistency as cells with , will trigger false-positive -rem if %min_column% neq %max_column% ( -rem echo ERROR - %flow_file%.csv has inconsistent # of columns | tee -a "%flow_file%.log" -rem ) if %min_column% lss 2 ( echo ERROR - %flow_file%.csv has has lesser than 2 columns | tee -a "%flow_file%.log" ) else ( @@ -551,13 +547,14 @@ if exist "tagui_chrome.in" ( rem check for which operating system and launch chrome accordingly set chrome_started=Windows - set chrome_switches=--remote-debugging-port=9222 about:blank + set chrome_switches=--user-data-dir=chrome\tagui_user_profile --remote-debugging-port=9222 about:blank if not exist "%chrome_command%" ( echo ERROR - cannot find Chrome at "%chrome_command%" echo update chrome_command setting in tagui\src\tagui.cmd to your chrome.exe exit /b 1 ) - taskkill /IM chrome.exe /T /F > nul 2>&1 + for /f "tokens=* usebackq" %%p in (`wmic process where "caption like '%%chrome.exe%%' and commandline like '%%tagui_user_profile --remote-debugging-port=9222%%'" get processid 2^>nul ^| cut -d" " -f 1 ^| sort -nur ^| head -n 1`) do set chrome_process_id=%%p + if not "!chrome_process_id!"=="" taskkill /PID !chrome_process_id! /T /F > nul 2>&1 start "" "%chrome_command%" !chrome_switches! !window_size! !headless_switch! :scan_ws_again @@ -587,8 +584,10 @@ if exist "tagui.sikuli\tagui_sikuli.in" echo finish > tagui.sikuli\tagui_sikuli. if exist "tagui_chrome.in" echo finish > tagui_chrome.in rem kill chrome processes by checking which os the processes are started on -if not "!chrome_started!"=="" if %tagui_speed_mode%==false taskkill /IM chrome.exe /T /F > nul 2>&1 - +if not "!chrome_started!"=="" if %tagui_speed_mode%==false ( + for /f "tokens=* usebackq" %%p in (`wmic process where "caption like '%%chrome.exe%%' and commandline like '%%tagui_user_profile --remote-debugging-port=9222%%'" get processid 2^>nul ^| cut -d" " -f 1 ^| sort -nur ^| head -n 1`) do set chrome_process_id=%%p + if not "!chrome_process_id!"=="" taskkill /PID !chrome_process_id! /T /F > nul 2>&1 +) rem end of big loop for managing multiple data sets in datatable ) :break_for_loop