Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

474
Views
¿Cómo acceder a la URL de un navegador o al archivo de una aplicación usando AXUIElementCopyAttributeValue o equivalente para Mac OS usando Swift?

Estoy tratando de obtener las URL que tiene abierto un navegador como safari (para cada ventana). Actualmente, obtengo todas las aplicaciones en ejecución en mi Mac y saco la aplicación de safari, por lo que puedo obtenerla como una 'NSRunningApplication'. Además, estoy tratando de encontrar el archivo que una aplicación como Final Cut Pro ha abierto para todas sus instancias.

Luego uso el siguiente código para intentar obtener las direcciones URL del navegador Safari:

 if AXUIElementCopyAttributeValue(appReference, "AXURL" as CFString, &urls) == .success { let url = urls as! [AXUIElement] print("url = \(url)") }

El código que utilizo para intentar obtener el documento de la instancia de Final Cut Pro es (no estoy seguro de cómo obtener el documento para cada instancia del programa):

 if AXUIElementCopyAttributeValue(appReference, "AXDocument" as CFString, &doc) == .success { let docReference = doc as! [AXUIElement] print("docReference = \(docReference)") }

este código solo devuelve una matriz de 'AXUIElement' que no estoy seguro de cómo obtener una URL.

¿Alguna idea sobre lo que podría estar faltando para extraer las direcciones URL actuales que tiene abierto el navegador Safari? Además, ¿alguna idea de lo que podría estar faltando para extraer el archivo para cada instancia (ventana) de un programa determinado? Me gustaría obtener todas las URL de cada ventana y de alguna manera distinguir qué ventana es cuál (por ejemplo, usar una matriz de matrices con URL en ellas).

Tenga en cuenta que estaba tratando de no usar el script de Apple, pero si conoce una buena solución y cómo podría integrarla en mi aplicación rápida, me encantaría escucharla.

over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Con AppleScript, puede usar NSAppleScript en Swift.

Ejemplo:

 set r to "" -- an empty variable for appending a string tell application "Safari" repeat with w in windows -- loop for each window, w is a variable which contain the window object if exists current tab of w then -- is a valid browser window repeat with t in tabs of w -- loop for each tab of this window, , t is a variable which contain the tab object -- get the title (name) of this tab and get the url of this tab tell t to set r to r & "Title : " & name & ", URL : " & URL & linefeed -- append a line to the variable (r) (* 'linefeed' mean a line break 'tell t' mean a tab of w (window) '&' is for concatenate strings, same as the + operator in Swift *) end repeat end if end repeat end tell return r -- return the string (each line contains a title and an URL)

El AppleScript devolverá una cadena, como esta :

 Title : the title of the first tab, URL : the url of the first tab Title : the title of the second tab, URL : the url of the second tab Title : the title of the third tab, URL : the url of the third tab ....

over 4 years ago · Santiago Trujillo Report

0

Buscaría en la propiedad kAXURLAttrubte. Es mejor usar que "AXURL"

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!