SPB Git

Repository Public

li_post_text.sh 4.2 KB 141 lines shellscript

1#!/bin/bash2# =============================================================================3#                  SP BOUCHER | INFRASTRUCTURE & AUTOMATION4#             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5# =============================================================================6#7# Project          : FB Ka Automation8# File             : li_post_text.sh9# Repository       : https://git.spboucher.ai/fb-ka-automation10# Created          : 2026-12-0111# Last Modified    : 2026-12-0112#13# Author           : Simon-Pierre Boucher14# Position         : Professor of Finance15# Institution      : Université du Québec en Outaouais (UQO)16# Organization     : SP Boucher17# Website          : https://spboucher.ai18# Git              : https://git.spboucher.ai19#20# Preferred Contact: contact@spboucher.ai21# Technical Contact: dev@spboucher.ai22# Security/Admin   : admin@spboucher.ai23#24# Copyright (c) 202625# Simon-Pierre Boucher26# All rights reserved where applicable. This file is governed by the27# applicable project license, copyright notices and relevant law.28# Existing third-party rights and notices remain unaffected.29#30# License          : None specified (no license file in this repository)31#32# Do not embed credentials, private keys, access tokens,33# certificates or confidential personal information.34#35# =============================================================================36# END OF SP BOUCHER SOURCE HEADER37# =============================================================================3839# Publie un post texte (le lien dans le texte génère l'aperçu) sur la page LinkedIn Groupe KA40set -u41TXT="$1"42WIN="${2:-13939}"4344js() {45  osascript <<EOF46tell application "Safari"47  do JavaScript "$1" in tab 1 of window id $WIN48end tell49EOF50}5152# 0) dashboard admin53osascript -e "tell application \"Safari\" to set URL of tab 1 of window id $WIN to \"https://www.linkedin.com/company/143347918/admin/dashboard/\""54sleep 105556# 1) Commencer un post (poll)57R=""58for i in 1 2 3 4 5 6; do59  R=$(js "60(function(){61  var btn=null;62  document.querySelectorAll('button, a, [role=button]').forEach(function(b){63    var t=(b.innerText||'').trim();64    if((/Commencer un post/.test(t)||/Créer un post/.test(t)) && !btn) btn=b;65  });66  if(!btn) return 'NO_BTN';67  btn.click();68  return 'clicked';69})();")70  echo "composer (essai $i): $R"71  [ "$R" = "clicked" ] && break72  sleep 473done74[ "$R" = "clicked" ] || exit 175sleep 67677# 2) texte78pbcopy < "$TXT"79R=""80for i in 1 2 3 4 5; do81  R=$(js "82(function(){83  var m=document.querySelector('.artdeco-modal, div[role=dialog]');84  if(!m) return 'NO_MODAL';85  var ed=m.querySelector('[contenteditable=true]');86  if(!ed) return 'NO_ED';87  ed.focus();88  return 'focused';89})();")90  echo "editor (essai $i): $R"91  [ "$R" = "focused" ] && break92  sleep 393done94[ "$R" = "focused" ] || exit 195LEN=096for i in 1 2 3; do97  osascript -e 'tell application "Safari" to activate' -e 'delay 0.8' -e 'tell application "System Events" to keystroke "v" using command down'98  sleep 399  LEN=$(js "100(function(){101  var m=document.querySelector('.artdeco-modal, div[role=dialog]');102  var ed=m?m.querySelector('[contenteditable=true]'):null;103  return ''+(ed?ed.innerText.length:-1);104})();")105  echo "texte len=$LEN (essai $i)"106  [ "$LEN" -gt 100 ] 2>/dev/null && break107  sleep 2108done109[ "$LEN" -gt 100 ] 2>/dev/null || { echo "paste failed"; exit 1; }110# laisser l'aperçu du lien se générer111sleep 6112113# 3) Publier114R=""115for i in 1 2 3 4 5; do116  R=$(js "117(function(){118  var m=document.querySelector('.artdeco-modal, div[role=dialog]');119  if(!m) return 'NO_MODAL';120  var btn=null;121  m.querySelectorAll('button').forEach(function(b){122    if((b.innerText||'').trim()==='Publier' && !b.disabled) btn=b;123  });124  if(!btn) return 'OFF';125  btn.click();126  return 'publie';127})();")128  echo "publier (essai $i): $R"129  [ "$R" = "publie" ] && break130  sleep 4131done132[ "$R" = "publie" ] || exit 1133for i in 1 2 3 4 5 6 7 8; do134  sleep 6135  N=$(js "document.querySelector('.artdeco-modal, div[role=dialog]') ? 'OPEN' : 'CLOSED';")136  echo "fermeture ($i): $N"137  [ "$N" = "CLOSED" ] && break138done139# la publication est asynchrone : Publier cliqué = succès probable, l'audit final confirme140echo "OK: $(basename "$TXT") publié sur LinkedIn (fermeture: $N)"141
Files main
Menu

Theme