├── .cursor ├── rules │ ├── agent.mdc │ ├── mcp-inspector.mdc │ └── safari.mdc └── safari.mdc ├── .github ├── dependabot.yml └── workflows │ ├── ci.yml │ └── publish.yml ├── .gitignore ├── .npmignore ├── .prettierignore ├── .prettierrc.json ├── .windsurfrules ├── CHANGELOG.md ├── CLAUDE.md ├── LICENSE ├── README.md ├── assets └── logo.png ├── docs ├── DEVELOPMENT.md ├── E2E_TESTING_STRATEGIES.md ├── applescript_beep.md ├── applescript_calendar_operations.md ├── applescript_choose_from_list.md ├── applescript_clipboard.md ├── applescript_display_dialog.md ├── applescript_finder_operations.md ├── applescript_kill_process_on_port.md ├── applescript_macos_version.md ├── applescript_network_operations.md ├── applescript_safari_url_operations.md ├── applescript_system_appearance.md ├── applescript_terminal_commands.md ├── automation-permissions-example.png ├── debugging_applescript.md ├── kb_validation.md └── spec.md ├── eslint.config.js ├── knowledge_base ├── 01_intro │ ├── _category_info.md │ ├── conventions_how_to_use_kb.md │ └── meta_open_dictionary.md ├── 02_as_core │ ├── _category_info.md │ ├── applescript_core_tell_application_block.md │ ├── handlers_and_subroutines │ │ ├── core_handler_on_idle.md │ │ ├── core_handler_on_open_droplet.md │ │ ├── core_handler_on_quit.md │ │ └── core_handler_on_reopen.md │ ├── operators │ │ ├── core_operator_arithmetic_extra.md │ │ ├── core_operator_coercion_as.md │ │ ├── core_operator_comparison_textual.md │ │ ├── core_operator_concat.md │ │ ├── core_operator_contains.md │ │ ├── core_operator_logical.md │ │ ├── core_operator_reference_to.md │ │ └── core_operator_string_prefix_suffix.md │ ├── reference_forms │ │ ├── core_reference_arbitrary.md │ │ ├── core_reference_filter_whose.md │ │ ├── core_reference_id.md │ │ ├── core_reference_index.md │ │ ├── core_reference_name.md │ │ ├── core_reference_property.md │ │ ├── core_reference_range.md │ │ └── core_reference_relative.md │ ├── scripting_additions_osax │ │ ├── offset_of_in.md │ │ ├── osax_beep.md │ │ ├── osax_choose_application.md │ │ ├── osax_choose_color.md │ │ ├── osax_choose_file.md │ │ ├── osax_choose_from_list.md │ │ ├── osax_choose_url.md │ │ ├── osax_current_date.md │ │ ├── osax_delay.md │ │ ├── osax_display_dialog.md │ │ ├── osax_do_shell_script.md │ │ ├── osax_file_read_write.md │ │ ├── osax_info_for.md │ │ ├── osax_list_disk_folder.md │ │ ├── osax_load_script.md │ │ ├── osax_path_to.md │ │ ├── osax_round.md │ │ ├── osax_run_script.md │ │ ├── osax_the_clipboard.md │ │ └── osax_time_to_gmt.md │ └── variables_and_data_types │ │ ├── constant_data_type.md │ │ ├── core_datatype_alias.md │ │ ├── core_datatype_boolean.md │ │ ├── core_datatype_date.md │ │ ├── core_datatype_integer.md │ │ ├── core_datatype_list.md │ │ ├── core_datatype_record.md │ │ ├── core_datatype_string.md │ │ └── data_data_type_raw.md ├── 03_jxa_core │ ├── _category_info.md │ ├── browser │ │ ├── jxa_chrome_operations.md │ │ ├── jxa_multi_browser_tab_management.md │ │ ├── jxa_safari_basic_operations.md │ │ └── jxa_safari_content_extraction.md │ ├── clipboard │ │ ├── jxa_clipboard_files.md │ │ ├── jxa_clipboard_images.md │ │ ├── jxa_clipboard_manager.md │ │ ├── jxa_clipboard_rich_text.md │ │ └── jxa_clipboard_text.md │ ├── file_operations │ │ ├── jxa_basic_file_operations.md │ │ ├── jxa_file_paths_and_aliases.md │ │ ├── jxa_folder_operations.md │ │ └── jxa_unicode_file_operations.md │ ├── json_processing │ │ ├── jxa_json_base.md │ │ ├── jxa_json_convert_format.md │ │ ├── jxa_json_fetch_api.md │ │ ├── jxa_json_merge.md │ │ ├── jxa_json_process_file.md │ │ ├── jxa_json_save_file.md │ │ └── jxa_json_transform_data.md │ ├── jxa_browser_automation.md │ ├── jxa_clipboard_operations.md │ ├── jxa_display_dialog_input.md │ ├── jxa_display_notification.md │ ├── jxa_do_shell_script.md │ ├── jxa_file_dialogs.md │ ├── jxa_file_operations.md │ ├── jxa_finder_interaction.md │ ├── jxa_introduction_syntax.md │ ├── jxa_json_api_processing.md │ ├── jxa_objc_bridge.md │ ├── jxa_system_appearance.md │ ├── jxa_system_events_ui_control.md │ ├── jxa_ui_automation.md │ ├── jxa_user_dialogs.md │ ├── system_events │ │ ├── jxa_application_menu_control.md │ │ ├── jxa_keystrokes.md │ │ ├── jxa_system_functions_control.md │ │ └── jxa_ui_elements_control.md │ └── ui_automation │ │ ├── jxa_ui_base.md │ │ ├── jxa_ui_click.md │ │ ├── jxa_ui_drag_drop.md │ │ ├── jxa_ui_element_values.md │ │ ├── jxa_ui_find_element.md │ │ ├── jxa_ui_hierarchy.md │ │ ├── jxa_ui_menu_actions.md │ │ ├── jxa_ui_scroll.md │ │ ├── jxa_ui_wait_element.md │ │ └── jxa_ui_window_info.md ├── 04_system │ ├── _category_info.md │ ├── audio_control │ │ ├── app_specific_volume.md │ │ ├── switch_audio_output.md │ │ └── system_volume_control.md │ ├── clipboard_system │ │ ├── clipboard_history_manager.md │ │ └── system_clipboard_get_file_paths.md │ ├── display_control │ │ └── system_display_brightness.md │ ├── notifications │ │ └── system_notification_center.md │ ├── power_management │ │ └── system_sleep_wake_control.md │ ├── screen_lock │ │ └── system_screen_lock.md │ ├── screen_time │ │ ├── screen_time_app_limits.md │ │ └── screen_time_get_usage.md │ ├── system_info │ │ └── system_information_retrieval.md │ ├── system_preferences_settings │ │ ├── appearance_control_concepts.md │ │ ├── date_time_timezone_settings.md │ │ ├── memory_mouse_concepts.md │ │ ├── network_location_switching.md │ │ ├── sound_output_input_selection.md │ │ ├── system_settings_network_toggle_wifi.md │ │ ├── system_settings_notifications.md │ │ ├── system_settings_open_pane.md │ │ ├── system_settings_toggle_dark_mode.md │ │ └── systemsettings_open_pane.md │ ├── system_settings │ │ └── system_preferences_control.md │ ├── ui_scripting_systemwide │ │ └── system_ui_click_menu_bar_item.md │ ├── volume_control │ │ └── system_volume_control.md │ └── window_management │ │ └── system_window_arrangement.md ├── 05_files │ ├── _category_info.md │ ├── backup_operations │ │ ├── system_backup │ │ │ ├── backup_core.md │ │ │ ├── backup_engine.md │ │ │ └── backup_scheduler.md │ │ └── system_backup_script.md │ ├── batch_operations │ │ ├── batch_apply_metadata.md │ │ ├── batch_convert_images.md │ │ ├── batch_move_organize_files.md │ │ ├── batch_rename_files.md │ │ └── folder_cleanup_operations.md │ ├── do_shell_script_for_files │ │ └── shell_list_directory_ls.md │ ├── file_operations_finder │ │ ├── finder_batch_rename_files.md │ │ ├── finder_create_new_folder.md │ │ ├── finder_get_selected_items_paths.md │ │ ├── finder_list_desktop_files.md │ │ └── finder_organize_files_by_type.md │ ├── file_operations_no_finder │ │ ├── fileops_read_text_file.md │ │ └── fileops_write_text_file.md │ ├── folder_operations_finder │ │ └── finder_create_new_folder_desktop.md │ ├── paths_and_references │ │ ├── paths_get_standard_folders.md │ │ ├── paths_posix_vs_hfs.md │ │ └── paths_user_select_file_folder.md │ └── security_operations │ │ └── file_encryption_decryption.md ├── 06_terminal │ ├── _category_info.md │ ├── coordination │ │ ├── terminal_broadcast_mode.md │ │ ├── terminal_echo_mode.md │ │ └── terminal_parallel_mode.md │ ├── file_operations │ │ ├── terminal_change_permissions.md │ │ ├── terminal_compress_files.md │ │ ├── terminal_copy_files.md │ │ ├── terminal_create_file.md │ │ ├── terminal_delete_files.md │ │ ├── terminal_extract_archive.md │ │ └── terminal_move_files.md │ ├── ghostty │ │ ├── ghostty_automation.md │ │ ├── ghostty_manage_titles.md │ │ └── ghostty_send_text.md │ ├── iterm │ │ ├── iterm_dev_environment.md │ │ ├── iterm_dynamic_profiles.md │ │ ├── iterm_manage_titles.md │ │ ├── iterm_send_text.md │ │ ├── iterm_session_management.md │ │ ├── iterm_split_pane.md │ │ ├── iterm_tmux_integration.md │ │ └── iterm_window_arrangement.md │ └── terminal_app │ │ ├── terminal_find_focus_window.md │ │ ├── terminal_find_kill_process_by_port.md │ │ ├── terminal_get_tab_content.md │ │ ├── terminal_manage_titles.md │ │ ├── terminal_open_close_window.md │ │ ├── terminal_run_command_and_get_output.md │ │ ├── terminal_send_control_character.md │ │ ├── terminal_session_management.md │ │ ├── terminal_split_pane.md │ │ └── terminal_window_arrangement.md ├── 07_browsers │ ├── _category_info.md │ ├── _common_browser_js_snippets │ │ ├── js_click_element.md │ │ ├── js_extract_all_links.md │ │ ├── js_get_element_by_id.md │ │ ├── js_get_page_ready_state.md │ │ └── js_get_set_input_value.md │ ├── chrome │ │ ├── chrome_accessibility_inspector.md │ │ ├── chrome_bookmark_operations.md │ │ ├── chrome_browser_automation.md │ │ ├── chrome_capture_screenshot.md │ │ ├── chrome_clear_browser_data.md │ │ ├── chrome_cors_disable.md │ │ ├── chrome_css_selector_finder.md │ │ ├── chrome_emulate_device.md │ │ ├── chrome_execute_javascript.md │ │ ├── chrome_execute_js_console.md │ │ ├── chrome_execute_js_get_result.md │ │ ├── chrome_form_filler.md │ │ ├── chrome_geolocation_spoofing.md │ │ ├── chrome_get_front_tab_url.md │ │ ├── chrome_inspect_element.md │ │ ├── chrome_intercept_network_requests.md │ │ ├── chrome_list_all_tabs.md │ │ ├── chrome_network_throttling.md │ │ ├── chrome_open_devtools.md │ │ ├── chrome_open_url_new_tab_profile.md │ │ ├── chrome_record_performance_trace.md │ │ └── chrome_test_runner.md │ ├── firefox │ │ ├── firefox_bookmark_current_page.md │ │ ├── firefox_capture_screenshot.md │ │ ├── firefox_close_current_tab.md │ │ ├── firefox_execute_js_get_result.md │ │ ├── firefox_get_front_tab_url.md │ │ ├── firefox_list_all_tabs.md │ │ ├── firefox_network_throttling.md │ │ ├── firefox_open_developer_tools.md │ │ ├── firefox_open_url.md │ │ ├── firefox_open_url_new_tab.md │ │ ├── firefox_refresh_page.md │ │ ├── firefox_responsive_design_mode.md │ │ ├── firefox_save_page_as_pdf.md │ │ ├── firefox_switch_to_tab_by_title.md │ │ └── firefox_toggle_private_browsing.md │ └── safari │ │ ├── safari_capture_screenshot.md │ │ ├── safari_clear_cache.md │ │ ├── safari_close_tab.md │ │ ├── safari_event_listener.md │ │ ├── safari_execute_console_command.md │ │ ├── safari_execute_js_get_result.md │ │ ├── safari_export_pdf.md │ │ ├── safari_form_filler.md │ │ ├── safari_form_manipulation.md │ │ ├── safari_get_bookmarks.md │ │ ├── safari_get_dom_info.md │ │ ├── safari_get_front_tab_url.md │ │ ├── safari_inject_script.md │ │ ├── safari_inspect_element.md │ │ ├── safari_list_all_tabs.md │ │ ├── safari_local_storage.md │ │ ├── safari_manage_bookmarks.md │ │ ├── safari_modify_dom.md │ │ ├── safari_network_monitor.md │ │ ├── safari_open_url.md │ │ ├── safari_open_url_new_tab.md │ │ ├── safari_open_web_inspector.md │ │ ├── safari_performance_analysis.md │ │ ├── safari_privacy_features.md │ │ ├── safari_reload_page.md │ │ ├── safari_save_bookmark.md │ │ ├── safari_save_page.md │ │ ├── safari_security_testing.md │ │ ├── safari_switch_tab.md │ │ └── safari_toggle_responsive_design_mode.md ├── 08_editors │ ├── _category_info.md │ ├── _common_ide_ui_patterns │ │ └── ide_ui_command_palette.md │ ├── browser_devtools │ │ └── devtools_capture_network_har.md │ ├── cursor │ │ └── cursor_ai_commands.md │ ├── electron_editors │ │ ├── electron_editors_devtools_js_inject.md │ │ ├── electron_editors_get_content_via_js_clipboard.md │ │ ├── electron_open_file_folder.md │ │ └── electron_vscode_get_editor_content_js.md │ ├── jetbrains │ │ ├── jetbrains_open_project.md │ │ └── jetbrains_run_action.md │ ├── sublime_text │ │ ├── _category_info.md │ │ ├── sublime_text_get_content.md │ │ ├── sublime_text_manipulate_text.md │ │ ├── sublime_text_open_file_folder.md │ │ ├── sublime_text_package_management.md │ │ ├── sublime_text_project_management.md │ │ └── sublime_text_run_command.md │ └── vscode │ │ ├── vscode_open_folder.md │ │ ├── vscode_run_command.md │ │ └── vscode_settings_sync.md ├── 09_productivity │ ├── _category_info.md │ ├── calendar_app │ │ ├── calendar_create_event.md │ │ ├── calendar_event_creator.md │ │ ├── calendar_find_events.md │ │ └── calendar_list_today_events.md │ ├── contacts_app │ │ ├── contacts_create_group.md │ │ ├── contacts_create_new_contact.md │ │ ├── contacts_export_vcard.md │ │ ├── contacts_list_all_contacts.md │ │ └── contacts_search_by_name.md │ ├── facetime_app │ │ ├── facetime_create_link.md │ │ ├── facetime_live_captions.md │ │ ├── facetime_record_call.md │ │ └── facetime_start_call.md │ ├── find_my_app │ │ ├── find_my_device_location.md │ │ ├── find_my_list_devices.md │ │ └── find_my_track_items.md │ ├── home_app │ │ ├── home_control_device.md │ │ ├── home_list_devices.md │ │ └── home_manage_automations.md │ ├── mail_app │ │ ├── automation │ │ │ ├── mail_apply_template_responses.md │ │ │ ├── mail_archive_old_messages.md │ │ │ ├── mail_automation_core.md │ │ │ ├── mail_create_email_digest.md │ │ │ ├── mail_create_quick_message.md │ │ │ ├── mail_email_composition.md │ │ │ ├── mail_organize_messages.md │ │ │ ├── mail_process_inbox_rules.md │ │ │ ├── mail_search_organization.md │ │ │ ├── mail_template_system.md │ │ │ └── mail_ui_components.md │ │ ├── mail_automation_script.md │ │ ├── mail_batch_archive.md │ │ ├── mail_check_for_replies.md │ │ ├── mail_compose_new_email_mailto.md │ │ ├── mail_create_rule.md │ │ ├── mail_create_smart_mailbox.md │ │ ├── mail_export_contacts.md │ │ ├── mail_flag_messages.md │ │ ├── mail_get_unread_count.md │ │ ├── mail_list_accounts_mailboxes.md │ │ ├── mail_move_messages.md │ │ ├── mail_save_attachments.md │ │ ├── mail_search_messages.md │ │ ├── mail_send_email_direct.md │ │ ├── mail_smart_reply.md │ │ ├── mail_statistics_report.md │ │ └── mail_summarize_inbox.md │ ├── maps_app │ │ ├── maps_get_current_location.md │ │ └── maps_search_location.md │ ├── messages_app │ │ ├── messages_create_group_chat.md │ │ ├── messages_get_chat_history.md │ │ ├── messages_get_recent_chats.md │ │ ├── messages_send_file.md │ │ ├── messages_send_message.md │ │ └── messages_set_status.md │ ├── notes_app │ │ ├── notes_create_folder.md │ │ ├── notes_create_plain_text_note.md │ │ └── notes_search_notes.md │ ├── reminders_app │ │ ├── reminders_create_list.md │ │ ├── reminders_create_reminder.md │ │ ├── reminders_create_reminder_complex.md │ │ └── reminders_list_due_today.md │ └── reminders_create_reminder.md ├── 10_creative │ ├── _category_info.md │ ├── books_app │ │ ├── books_get_current_book.md │ │ └── books_open_book.md │ ├── garageband │ │ ├── _category_info.md │ │ ├── garageband_basic_controls.md │ │ ├── garageband_project_management.md │ │ └── garageband_smart_controls.md │ ├── image_events_app │ │ ├── audio_conversion_utility.md │ │ ├── image_conversion_utility.md │ │ ├── image_events_get_dimensions.md │ │ └── video_conversion_utility.md │ ├── keynote_app │ │ ├── keynote_add_slide_master.md │ │ ├── keynote_create_presentation_theme.md │ │ ├── keynote_export_presentation.md │ │ ├── keynote_presenter_notes.md │ │ ├── keynote_set_slide_text.md │ │ └── keynote_slideshow_control.md │ ├── logic_pro │ │ ├── _category_info.md │ │ ├── logic_pro_basic_controls.md │ │ ├── logic_pro_project_management.md │ │ └── logic_pro_scripter_midi.md │ ├── music_app │ │ ├── music_current_track_info.md │ │ ├── music_library_management.md │ │ ├── music_playback_controls.md │ │ ├── music_playlist_operations.md │ │ ├── music_repeat_shuffle_control.md │ │ └── music_search_and_play.md │ ├── numbers_app │ │ ├── numbers_create_chart.md │ │ ├── numbers_create_spreadsheet.md │ │ ├── numbers_edit_cell_formula.md │ │ └── numbers_export_as_csv.md │ ├── pages_app │ │ ├── pages_create_document.md │ │ ├── pages_document_analysis.md │ │ ├── pages_export_as_pdf.md │ │ ├── pages_manage_styles.md │ │ ├── pages_table_operations.md │ │ └── pages_template_operations.md │ ├── photos_app │ │ ├── photos_create_album.md │ │ ├── photos_export_photos.md │ │ ├── photos_get_selected_items.md │ │ └── photos_slideshow.md │ ├── podcasts_app │ │ ├── podcasts_list_subscriptions.md │ │ └── podcasts_play_episode.md │ ├── preview_app │ │ ├── preview_export_pdf_as_image.md │ │ └── preview_open_file.md │ ├── quicktime_player_app │ │ ├── quicktime_open_video.md │ │ └── quicktime_record_screen.md │ ├── spotify │ │ ├── _category_info.md │ │ ├── spotify_current_track_info.md │ │ ├── spotify_keyboard_control.md │ │ ├── spotify_playback_controls.md │ │ ├── spotify_playback_position.md │ │ ├── spotify_playlist_operations.md │ │ ├── spotify_repeat_shuffle_control.md │ │ ├── spotify_save_current_track.md │ │ ├── spotify_search_and_play.md │ │ └── spotify_uri_handler.md │ ├── textedit_app │ │ └── textedit_get_set_text.md │ ├── tv_app │ │ ├── tv_get_current_playback.md │ │ └── tv_play_movie.md │ ├── vlc │ │ ├── _category_info.md │ │ ├── vlc_current_media_info.md │ │ ├── vlc_open_media.md │ │ └── vlc_playback_controls.md │ └── voice_memos_app │ │ ├── voice_memos_list_recordings.md │ │ └── voice_memos_record_new.md ├── 11_advanced │ ├── _category_info.md │ ├── handling_large_data_and_performance │ │ └── advanced_large_data_performance.md │ ├── inter_app_communication_advanced │ │ ├── 01_raw_apple_events.md │ │ ├── 02_using_terms_from_application.md │ │ ├── 03_ignoring_application_responses.md │ │ └── 04_considering_ignoring_attributes.md │ └── workflow_automation │ │ ├── pomodoro_focus.md │ │ └── pomodoro_timer.md ├── 12_network │ ├── 01_ftp_operations_url_access.md │ ├── 03_networksetup_cli_basics.md │ ├── 04_sharing_services_status.md │ ├── _category_info.md │ ├── port_management │ │ └── find_kill_process_by_port.md │ └── wifi_management │ │ └── network_wifi_management.md ├── 13_developer │ ├── _category_info.md │ ├── app_store_app │ │ ├── app_store_open_account.md │ │ └── app_store_search.md │ ├── calculator_app │ │ ├── calculator_perform_calculation.md │ │ └── calculator_switch_view.md │ ├── dictionary_app │ │ ├── dictionary_look_up_word.md │ │ └── dictionary_switch_dictionary.md │ ├── docker │ │ └── docker_container_controller.md │ ├── font_book_app │ │ ├── font_book_list_fonts.md │ │ └── font_book_search_font.md │ ├── git │ │ └── git_commit_push.md │ ├── kaleidoscope │ │ ├── kaleidoscope_cli_integration.md │ │ ├── kaleidoscope_compare_clipboard.md │ │ ├── kaleidoscope_compare_files.md │ │ ├── kaleidoscope_dev_tools_integration.md │ │ ├── kaleidoscope_file_version_tracker.md │ │ ├── kaleidoscope_view_git_changeset.md │ │ └── kaleidoscope_view_git_history.md │ ├── parallels_desktop │ │ ├── parallels_desktop_controller.md │ │ ├── parallels_desktop_vm_controller.md │ │ └── parallels_desktop_vm_management.md │ ├── script_editor_app │ │ ├── script_editor_compile_document.md │ │ ├── script_editor_compile_run.md │ │ ├── script_editor_get_text.md │ │ ├── script_editor_open_file.md │ │ ├── script_editor_run_document.md │ │ ├── script_editor_save_as_app.md │ │ ├── script_editor_save_document.md │ │ └── script_editor_set_text.md │ ├── security │ │ └── keychain_access │ │ │ ├── 01_list_keychains.md │ │ │ ├── 02_get_password_from_keychain.md │ │ │ ├── 03_add_generic_password_to_keychain.md │ │ │ └── 04_lock_unlock_keychain.md │ ├── shortcuts_app │ │ ├── shortcuts_create_folder.md │ │ ├── shortcuts_list_all.md │ │ └── shortcuts_run_by_name.md │ ├── things │ │ ├── things_complete_todo.md │ │ ├── things_create_area.md │ │ ├── things_create_project.md │ │ ├── things_create_tag.md │ │ ├── things_create_todo.md │ │ ├── things_get_todos.md │ │ ├── things_project_management.md │ │ ├── things_review_automation.md │ │ └── things_url_scheme.md │ ├── virtualbuddy │ │ ├── virtualbuddy_automation.md │ │ └── virtualbuddy_controller.md │ ├── vmware_fusion │ │ ├── _category_info.md │ │ └── vmware_fusion_controller.md │ └── xcode_app │ │ ├── ios_simulator_accessibility.md │ │ ├── ios_simulator_accessibility_inspector.md │ │ ├── ios_simulator_add_photos.md │ │ ├── ios_simulator_biometric_auth.md │ │ ├── ios_simulator_biometric_enrollment.md │ │ ├── ios_simulator_boot_device.md │ │ ├── ios_simulator_change_language.md │ │ ├── ios_simulator_clone_device.md │ │ ├── ios_simulator_create_device.md │ │ ├── ios_simulator_developer_settings.md │ │ ├── ios_simulator_icloud_sync.md │ │ ├── ios_simulator_install_app.md │ │ ├── ios_simulator_keyboard_settings.md │ │ ├── ios_simulator_launch_arguments.md │ │ ├── ios_simulator_list_devices.md │ │ ├── ios_simulator_monitor_logs.md │ │ ├── ios_simulator_open_url.md │ │ ├── ios_simulator_pasteboard.md │ │ ├── ios_simulator_performance_report.md │ │ ├── ios_simulator_privacy_permissions.md │ │ ├── ios_simulator_record_video.md │ │ ├── ios_simulator_reset_app_data.md │ │ ├── ios_simulator_rotate_device.md │ │ ├── ios_simulator_send_notification.md │ │ ├── ios_simulator_set_location.md │ │ ├── ios_simulator_shake_gesture.md │ │ ├── ios_simulator_status_bar.md │ │ ├── ios_simulator_status_bar_advanced.md │ │ ├── ios_simulator_toggle_appearance.md │ │ ├── ios_simulator_touch_indicators.md │ │ ├── xcode_archive_project.md │ │ ├── xcode_build_project_shell.md │ │ ├── xcode_build_project_ui.md │ │ ├── xcode_clean_derived_data.md │ │ ├── xcode_clean_project.md │ │ ├── xcode_extract_project_info.md │ │ ├── xcode_get_project_info_jxa.md │ │ ├── xcode_launch_simulator.md │ │ ├── xcode_open_instruments.md │ │ ├── xcode_open_project.md │ │ ├── xcode_reset_all_simulators.md │ │ ├── xcode_run_project.md │ │ ├── xcode_run_ui_tests.md │ │ ├── xcode_run_unit_tests.md │ │ └── xcode_switch_scheme.md └── _shared_handlers │ ├── _category_info.md │ ├── file_system_helpers.applescript │ └── string_utils.applescript ├── package-lock.json ├── package.json ├── scripts ├── fix-categories.ts ├── fix-subdirectory-categories.ts ├── kbFileValidator.ts ├── kbPathProcessor.ts ├── kbReport.ts ├── run-server-in-ci.sh ├── scriptValidator.ts ├── test-validator.ts └── validate-kb.ts ├── src ├── ScriptExecutor.ts ├── logger.ts ├── placeholderSubstitutor.ts ├── schemas.ts ├── server.ts ├── services │ ├── KnowledgeBaseManager.ts │ ├── kbLoader.ts │ ├── knowledgeBaseService.ts │ └── scriptingKnowledge.types.ts └── types.ts ├── start.sh ├── tests └── mcp-inspector.test.ts └── tsconfig.json /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: "npm" 4 | directory: "/" 5 | schedule: 6 | interval: "weekly" 7 | open-pull-requests-limit: 10 8 | 9 | - package-ecosystem: "github-actions" 10 | directory: "/" 11 | schedule: 12 | interval: "monthly" 13 | open-pull-requests-limit: 5 -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | name: Publish Package 2 | 3 | on: 4 | release: 5 | types: [created] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - uses: actions/checkout@v4 12 | - uses: actions/setup-node@v4 13 | with: 14 | node-version: '20.x' 15 | registry-url: 'https://registry.npmjs.org' 16 | 17 | - name: Install dependencies 18 | run: npm ci 19 | 20 | - name: Lint 21 | run: npm run lint 22 | 23 | - name: Validate Knowledge Base 24 | run: npm run validate-kb 25 | 26 | - name: Build 27 | run: npm run build 28 | 29 | - name: Publish 30 | run: npm publish --access public 31 | env: 32 | NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Dependency directories 2 | node_modules/ 3 | jspm_packages/ 4 | 5 | # Build output 6 | dist/ 7 | build/ 8 | out/ 9 | lib/ 10 | *.tsbuildinfo 11 | 12 | # Coverage directories 13 | coverage/ 14 | .nyc_output/ 15 | 16 | # Logs 17 | logs/ 18 | *.log 19 | npm-debug.log* 20 | yarn-debug.log* 21 | yarn-error.log* 22 | lerna-debug.log* 23 | 24 | # Environment variables 25 | .env 26 | .env.local 27 | .env.development.local 28 | .env.test.local 29 | .env.production.local 30 | 31 | # OS specific files 32 | .DS_Store 33 | Thumbs.db 34 | Desktop.ini 35 | 36 | # Editor directories and files 37 | .idea/ 38 | .vscode/ 39 | *.sublime-project 40 | *.sublime-workspace 41 | *.suo 42 | *.ntvs* 43 | *.njsproj 44 | *.sln 45 | *.sw? 46 | 47 | # Temporary files 48 | *.tmp 49 | *.temp 50 | .cache/ 51 | .eslintcache 52 | .npm/ 53 | 54 | # Debug files 55 | .node_repl_history 56 | 57 | # Optional npm cache directory 58 | .npm 59 | 60 | # Optional eslint cache 61 | .eslintcache 62 | 63 | # TypeScript cache 64 | *.tsbuildinfo 65 | 66 | # Output of 'npm pack' 67 | *.tgz 68 | 69 | # Generated JavaScript files from TypeScript scripts 70 | scripts/*.js 71 | 72 | # Validation output file 73 | validation-output.txt 74 | test_output.txt -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | # Ignore everything except explicitly included files in package.json 2 | * 3 | 4 | # Explicitly do not ignore the knowledge_base dir and dist dir 5 | !/knowledge_base/ 6 | !/dist/ 7 | !/README.md 8 | !/LICENSE -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | dist 3 | package-lock.json -------------------------------------------------------------------------------- /.prettierrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "semi": true, 3 | "trailingComma": "all", 4 | "singleQuote": true, 5 | "printWidth": 80, 6 | "tabWidth": 2 7 | } 8 | -------------------------------------------------------------------------------- /.windsurfrules: -------------------------------------------------------------------------------- 1 | AGENT.md -------------------------------------------------------------------------------- /CLAUDE.md: -------------------------------------------------------------------------------- 1 | .cursor/rules/agent.mdc -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 steipete 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /assets/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/steipete/macos-automator-mcp/3e98b906909d68e466acc47e85bdc0c264017e0c/assets/logo.png -------------------------------------------------------------------------------- /docs/applescript_beep.md: -------------------------------------------------------------------------------- 1 | # System Sound Notification in AppleScript 2 | 3 | AppleScript's `beep` command provides a simple way to create audible notifications. This document explains how to use this feature. 4 | 5 | ## Basic Beep 6 | 7 | ```applescript 8 | -- Play one beep (default) 9 | beep 10 | 11 | return "Played one beep" 12 | ``` 13 | 14 | ## Multiple Beeps 15 | 16 | ```applescript 17 | -- Play three beeps 18 | beep 3 19 | 20 | return "Played 3 beeps" 21 | ``` 22 | 23 | ## Beep with Error Handling 24 | 25 | ```applescript 26 | try 27 | beep 3 28 | return "Played 3 beeps (if sound is on)" 29 | on error errMsg 30 | return "Error beeping: " & errMsg 31 | end try 32 | ``` 33 | 34 | ## Notes 35 | 36 | - The actual sound played depends on the System Settings > Sound > Sound Effects settings 37 | - The system alert sound might be muted if the user has sound effects turned off 38 | - The `beep` command doesn't return a value 39 | - You can specify the number of beeps (integer parameter) 40 | - Useful for providing simple audible feedback in scripts 41 | - A complementary command is `display notification`, which shows visual notifications -------------------------------------------------------------------------------- /docs/applescript_macos_version.md: -------------------------------------------------------------------------------- 1 | # Get macOS Version with AppleScript 2 | 3 | There are two effective ways to get the current macOS version using AppleScript. This document explains both methods. 4 | 5 | ## Method 1: Using System Events 6 | 7 | This is a pure AppleScript approach that uses System Events to retrieve system information: 8 | 9 | ```applescript 10 | tell application "System Events" 11 | set osVersion to system version of (get system info) 12 | end tell 13 | return "macOS Version: " & osVersion 14 | ``` 15 | 16 | ## Method 2: Using Shell Commands 17 | 18 | This approach uses the `sw_vers` command-line tool via `do shell script` to get more detailed version information: 19 | 20 | ```applescript 21 | set productVersion to do shell script "sw_vers -productVersion" 22 | set buildVersion to do shell script "sw_vers -buildVersion" 23 | return "macOS Product Version: " & productVersion & return & "Build Version: " & buildVersion 24 | ``` 25 | 26 | ## Combined Approach 27 | 28 | For the most comprehensive version information: 29 | 30 | ```applescript 31 | -- Get version using System Events 32 | tell application "System Events" 33 | set osVersion to system version of (get system info) 34 | end tell 35 | 36 | -- Get more detailed version info via shell commands 37 | set productVersion to do shell script "sw_vers -productVersion" 38 | set buildVersion to do shell script "sw_vers -buildVersion" 39 | set productName to do shell script "sw_vers -productName" 40 | 41 | -- Format the output 42 | set versionInfo to "Product Name: " & productName & return 43 | set versionInfo to versionInfo & "Product Version: " & productVersion & return 44 | set versionInfo to versionInfo & "Build Version: " & buildVersion & return 45 | set versionInfo to versionInfo & "System Events Version: " & osVersion 46 | 47 | return versionInfo 48 | ``` 49 | 50 | ## Notes 51 | 52 | - The System Events method (`system version`) returns a simplified version string (e.g., "13.4.1") 53 | - The `sw_vers` command provides more detailed information, including build number 54 | - `sw_vers` also allows you to get just specific components with flags: 55 | - `-productName`: Gets macOS product name (e.g., "macOS") 56 | - `-productVersion`: Gets version number (e.g., "13.4.1") 57 | - `-buildVersion`: Gets build number (e.g., "22F82") 58 | - This script requires no special permissions to run 59 | - Version information is useful for scripts that need to behave differently based on the macOS version -------------------------------------------------------------------------------- /docs/applescript_terminal_commands.md: -------------------------------------------------------------------------------- 1 | # AppleScript: Terminal Command Execution 2 | 3 | This document demonstrates how to execute Terminal commands from AppleScript. This capability allows you to automate command-line operations and incorporate shell commands into your AppleScript workflows. 4 | 5 | ## Basic Usage 6 | 7 | ```applescript 8 | -- Run a command in a new Terminal tab 9 | tell application "Terminal" 10 | activate 11 | do script "ls -la ~/" 12 | end tell 13 | ``` 14 | 15 | ## How It Works 16 | 17 | 1. The script uses Terminal.app's AppleScript dictionary to interact with the application 18 | 2. `activate` brings Terminal to the foreground 19 | 3. `do script` tells Terminal to execute the specified shell command 20 | 4. By default, this creates a new tab (or window if none exist) and runs the command there 21 | 22 | ## Advanced Usage: Run Command in Existing Tab 23 | 24 | ```applescript 25 | tell application "Terminal" 26 | -- Run in the frontmost tab if it exists 27 | if (count of windows) > 0 then 28 | do script "echo 'Running in current tab'" in front window 29 | else 30 | -- Otherwise create a new tab 31 | do script "echo 'Created new tab'" 32 | end if 33 | end tell 34 | ``` 35 | 36 | ## Common Use Cases 37 | 38 | - Running system maintenance commands 39 | - Starting development servers 40 | - Executing scripts that require a terminal environment 41 | - Automating installation or update processes 42 | - Running network diagnostics or monitoring commands 43 | 44 | ## Notes and Limitations 45 | 46 | - Commands run asynchronously by default - the script continues without waiting for command completion 47 | - For commands that require user input, you'll need to prepare for interactive sessions 48 | - To run commands that require sudo, it's better to use the `do shell script` command with administrator privileges 49 | - The terminal window remains open after command execution - you would need additional scripting to close it automatically -------------------------------------------------------------------------------- /docs/automation-permissions-example.png: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /eslint.config.js: -------------------------------------------------------------------------------- 1 | import eslint from '@eslint/js'; 2 | import tseslint from 'typescript-eslint'; 3 | import prettierConfig from 'eslint-config-prettier'; 4 | 5 | export default tseslint.config( 6 | eslint.configs.recommended, 7 | ...tseslint.configs.recommended, 8 | prettierConfig, 9 | { 10 | ignores: ['node_modules/**', 'dist/**'], 11 | }, 12 | { 13 | languageOptions: { 14 | ecmaVersion: 2020, 15 | sourceType: 'module', 16 | parserOptions: { 17 | ecmaVersion: 2020, 18 | sourceType: 'module', 19 | }, 20 | globals: { 21 | // Node.js globals 22 | process: 'readonly', 23 | module: 'readonly', 24 | require: 'readonly', 25 | __dirname: 'readonly', 26 | __filename: 'readonly', 27 | console: 'readonly', 28 | }, 29 | }, 30 | linterOptions: { 31 | reportUnusedDisableDirectives: true, 32 | }, 33 | rules: { 34 | // Add any project-specific rules here 35 | }, 36 | } 37 | ); -------------------------------------------------------------------------------- /knowledge_base/01_intro/_category_info.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "README and Conventions" 3 | description: "Documentation about how to use and contribute to the knowledge base, and general conventions for AppleScript and JXA." 4 | category: "01_intro" 5 | --- 6 | 7 | This category contains information about how to use the knowledge base effectively, including conventions, naming standards, and organizational guidelines. It serves as the first place to start for understanding how scripts are organized and structured throughout the collection. -------------------------------------------------------------------------------- /knowledge_base/02_as_core/_category_info.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "AppleScript Core" 3 | description: "Core AppleScript language features, syntax, data types, operators, and standard scripting additions." 4 | category: "02_as_core" 5 | --- 6 | 7 | This category covers fundamental AppleScript language constructs and features. It includes information about data types, variables, operators, control flow, handlers (functions), and standard scripting additions (OSAX) that are built into macOS. These building blocks form the foundation for all AppleScript automation. -------------------------------------------------------------------------------- /knowledge_base/02_as_core/applescript_core_tell_application_block.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'AppleScript Core: Basic ''tell application'' Block' 3 | category: 02_as_core 4 | id: applescript_core_tell_application_block 5 | description: The fundamental structure for sending commands to a macOS application. 6 | keywords: 7 | - tell 8 | - application 9 | - syntax 10 | - basic 11 | - core 12 | language: applescript 13 | --- 14 | 15 | To control an application or get information from it, you use a `tell application` block. 16 | 17 | ```applescript 18 | tell application "Finder" 19 | -- Commands for the Finder go here 20 | set desktopItems to count of items on desktop 21 | activate -- Brings Finder to the front 22 | return "Finder has " & desktopItems & " items on the desktop." 23 | end tell 24 | ``` 25 | 26 | **Note:** Replace `"Finder"` with the exact name of the application you want to script (e.g., `"Safari"`, `"Mail"`, `"System Events"`). The application must be scriptable. 27 | END_TIP 28 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/handlers_and_subroutines/core_handler_on_idle.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Stay-Open Applet Handler ''on idle''' 3 | category: 02_as_core 4 | id: core_handler_on_idle 5 | description: >- 6 | Defines a handler that executes periodically if the script is saved as a 'Stay 7 | Open' application. Returning a number sets the next idle interval in seconds. 8 | keywords: 9 | - handler 10 | - idle 11 | - stay open 12 | - applet 13 | - background task 14 | - periodic 15 | language: applescript 16 | notes: > 17 | - Script must be saved as an Application with the "Stay open after run 18 | handler" checkbox checked. 19 | 20 | - The `idle` handler is called automatically by the system. 21 | 22 | - `return ` sets how long to wait before the next `idle` 23 | call. Default is 30 seconds if no value or an invalid value is returned. 24 | --- 25 | 26 | ```applescript 27 | -- This stay-open applet will display the current time every 10 seconds. 28 | 29 | property lastTimeDisplayed : "" 30 | 31 | on idle 32 | set currentTimeString to time string of (current date) 33 | if currentTimeString is not lastTimeDisplayed then 34 | -- display notification currentTimeString with title "Idle Check" -- Can be annoying 35 | log "Idle tick: " & currentTimeString -- Check Script Editor log 36 | set lastTimeDisplayed to currentTimeString 37 | end if 38 | return 10 -- Check again in 10 seconds 39 | end idle 40 | 41 | -- Optional: on run handler is executed once when the applet first launches 42 | on run 43 | log "Stay-open applet started. Idle handler will run periodically." 44 | -- Perform initial setup if any 45 | end run 46 | 47 | -- Optional: on quit handler for cleanup when the applet is quit 48 | on quit 49 | log "Stay-open applet quitting." 50 | -- Perform cleanup 51 | continue quit -- Allow the applet to actually quit 52 | end quit 53 | ``` 54 | END_TIP 55 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/handlers_and_subroutines/core_handler_on_open_droplet.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Droplet Handler ''on open''' 3 | category: 02_as_core 4 | id: core_handler_on_open_droplet 5 | description: >- 6 | Defines a handler that executes when files or folders are dropped onto the 7 | saved script (applet). The input is a list of aliases to the dropped items. 8 | keywords: 9 | - handler 10 | - droplet 11 | - on open 12 | - drag and drop 13 | - file processing 14 | - alias list 15 | language: applescript 16 | notes: > 17 | - Save the script as an Application to create a droplet. 18 | 19 | - `listOfDroppedItems` will be a list, even if only one item is dropped. 20 | 21 | - Each item in the list is an `alias`. Coerce to `POSIX path` for shell 22 | commands. 23 | --- 24 | 25 | ```applescript 26 | -- This script, when saved as an application (droplet), 27 | -- will display the POSIX paths of all items dropped onto it. 28 | 29 | on open listOfDroppedItems 30 | set outputPaths to {} 31 | try 32 | repeat with anItem in listOfDroppedItems 33 | set end of outputPaths to POSIX path of anItem 34 | end repeat 35 | 36 | if outputPaths is {} then 37 | display dialog "No valid items were processed." 38 | else 39 | set AppleScript's text item delimiters to "\\n" 40 | set displayMessage to "Dropped item paths:\\n" & (outputPaths as string) 41 | set AppleScript's text item delimiters to "" 42 | display dialog displayMessage 43 | end if 44 | 45 | on error errMsg number errNum 46 | display dialog "Error processing dropped items (" & errNum & "):\\n" & errMsg 47 | end try 48 | end open 49 | ``` 50 | END_TIP 51 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/operators/core_operator_arithmetic_extra.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Arithmetic Operators (div, mod, ^)' 3 | category: 02_as_core 4 | id: core_operator_arithmetic_extra 5 | description: >- 6 | Covers the integer division (div), modulo (mod), and exponentiation (^) 7 | operators. 8 | keywords: 9 | - operator 10 | - arithmetic 11 | - div 12 | - mod 13 | - power 14 | - exponentiation 15 | - integer division 16 | - remainder 17 | language: applescript 18 | notes: | 19 | - `div` performs integer division, truncating any fractional part. 20 | - `mod` returns the remainder of an integer division. 21 | - `^` raises a number to a power. 22 | --- 23 | 24 | These operators handle specific mathematical operations. 25 | 26 | ```applescript 27 | -- Integer Division (div) 28 | set intResult1 to 10 div 3 -- Result: 3 (10 / 3 = 3.33..., truncated) 29 | set intResult2 to 9 div 3 -- Result: 3 30 | set intResult3 to 7 div 2 -- Result: 3 31 | set intResult4 to -10 div 3 -- Result: -3 32 | 33 | -- Modulo (mod) - Remainder 34 | set modResult1 to 10 mod 3 -- Result: 1 (10 = 3*3 + 1) 35 | set modResult2 to 9 mod 3 -- Result: 0 36 | set modResult3 to 7 mod 2 -- Result: 1 37 | set modResult4 to -10 mod 3 -- Result: -1 (AppleScript's mod can be tricky with negative numbers, it's often `a mod n = a - n * (a div n)`) 38 | -- For a positive remainder with negative numbers, you might need: `set positiveMod to ((-10 mod 3) + 3) mod 3` which gives 2 39 | 40 | -- Exponentiation (^) 41 | set powerResult1 to 2 ^ 3 -- Result: 8 (2 * 2 * 2) 42 | set powerResult2 to 10 ^ 2 -- Result: 100 43 | set powerResult3 to 5 ^ 0.5 -- Result: 2.2360679775 (square root) 44 | set powerResult4 to 4 ^ -1 -- Result: 0.25 (1/4) 45 | 46 | return "10 div 3: " & intResult1 & ¬ 47 | "\n-10 div 3: " & intResult4 & ¬ 48 | "\n10 mod 3: " & modResult1 & ¬ 49 | "\n-10 mod 3: " & modResult4 & ¬ 50 | "\n2 ^ 3: " & powerResult1 & ¬ 51 | "\n5 ^ 0.5: " & powerResult3 52 | ``` 53 | END_TIP 54 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/operators/core_operator_comparison_textual.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Textual Comparison Operators' 3 | category: 02_as_core 4 | id: core_operator_comparison_textual 5 | description: >- 6 | Covers textual comparison operators in AppleScript like 'comes before', 'comes 7 | after', and their negations. 8 | keywords: 9 | - operator 10 | - comparison 11 | - comes before 12 | - comes after 13 | - is not less than 14 | - is not greater than 15 | - string comparison 16 | - lexicographical 17 | language: applescript 18 | notes: > 19 | - These operators primarily compare strings lexicographically 20 | (alphabetically). 21 | 22 | - Can also be used with numbers, where they behave like their symbolic 23 | counterparts (`<`, `>`, `>=`, `<=`). 24 | 25 | - `is less than`, `is greater than`, `is less than or equal to`, `is greater 26 | than or equal to` are synonyms for symbolic operators but can also be used. 27 | --- 28 | 29 | AppleScript offers English-like comparison operators, especially useful for strings. 30 | 31 | ```applescript 32 | -- String comparisons 33 | set strA to "apple" 34 | set strB to "banana" 35 | 36 | set aBeforeB to strA comes before strB -- true 37 | set bAfterA to strB comes after strA -- true 38 | 39 | set strC to "apple" 40 | set aNotAfterC to not (strA comes after strC) -- true (equivalent to strA is not greater than strC) 41 | set aNotBeforeC to not (strA comes before strC) -- false (equivalent to strA is not less than strC) 42 | 43 | -- Using 'is not less than' and 'is not greater than' 44 | set x to 10 45 | set y to 5 46 | set z to 10 47 | 48 | set xNotLessThanY to x is not less than y -- true (10 is not < 5) 49 | set yNotGreaterThanX to y is not greater than x -- true (5 is not > 10) 50 | set xNotLessThanZ to x is not less than z -- true (10 is not < 10, i.e. 10 >= 10) 51 | set xNotGreaterThanZ to x is not greater than z -- true (10 is not > 10, i.e. 10 <= 10) 52 | 53 | -- Numeric comparisons (behave like symbolic operators) 54 | set numComparison1 to 5 comes before 10 -- true (5 < 10) 55 | set numComparison2 to 10 comes after 5 -- true (10 > 5) 56 | set numComparison3 to 7 is not less than 7 -- true (7 >= 7) 57 | 58 | return "strA comes before strB: " & aBeforeB & ¬ 59 | "\nstrB comes after strA: " & bAfterA & ¬ 60 | "\nx is not less than y: " & xNotLessThanY & ¬ 61 | "\ny is not greater than x: " & yNotGreaterThanX & ¬ 62 | "\nx is not less than z: " & xNotLessThanZ & ¬ 63 | "\nx is not greater than z: " & xNotGreaterThanZ 64 | ``` 65 | END_TIP 66 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/operators/core_operator_concat.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Concatenation Operator (&)' 3 | category: 02_as_core 4 | id: core_operator_concat 5 | description: >- 6 | The ampersand (&) operator is used to concatenate (join) strings, lists, or 7 | add properties to records. 8 | keywords: 9 | - operator 10 | - concatenate 11 | - join 12 | - string 13 | - list 14 | - record 15 | - '&' 16 | language: applescript 17 | --- 18 | 19 | ```applescript 20 | -- String concatenation 21 | set str1 to "Hello" 22 | set str2 to "World" 23 | set combinedString to str1 & " " & str2 & "!" -- "Hello World!" 24 | 25 | -- List concatenation 26 | set list1 to {1, 2} 27 | set list2 to {3, 4} 28 | set combinedList to list1 & list2 -- {1, 2, 3, 4} 29 | set combinedListAndItem to list1 & 5 -- {1, 2, 5} 30 | 31 | -- Record concatenation (adds/overwrites properties) 32 | set record1 to {name:"Apple"} 33 | set record2 to {color:"Red"} 34 | set combinedRecord to record1 & record2 -- {name:"Apple", color:"Red"} 35 | set record3 to {name:"Banana", type:"Fruit"} 36 | set updatedRecord1 to record1 & record3 -- {name:"Banana", type:"Fruit"} (name is overwritten) 37 | 38 | return "String: " & combinedString & "\\nList: " & (combinedList as string) & "\\nRecord: " & (text 1 thru 30 of (combinedRecord as string)) -- Coercing record to string is verbose 39 | ``` 40 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/operators/core_operator_contains.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: ''contains'' Operator' 3 | category: 02_as_core 4 | id: core_operator_contains 5 | description: >- 6 | Checks if a list, record, or string contains another item or substring. 7 | Returns boolean. 8 | keywords: 9 | - operator 10 | - contains 11 | - is in 12 | - substring 13 | - list membership 14 | - record key 15 | language: applescript 16 | --- 17 | 18 | The `contains` operator (and its synonym `is in`) is versatile for checking inclusion. 19 | 20 | ```applescript 21 | -- String contains substring 22 | set myString to "Hello World" 23 | set hasHello to myString contains "Hello" -- true 24 | set hasEarth to myString contains "Earth" -- false 25 | 26 | -- List contains item 27 | set myList to {"apple", "banana", "cherry"} 28 | set hasBanana to myList contains "banana" -- true 29 | set hasDate to myList contains "date" -- false 30 | set isOneInList to 1 is in {1, 2, 3} -- true (using 'is in') 31 | 32 | -- Record contains key-value pair (less common for 'contains', usually check properties) 33 | -- 'contains' for records checks if the right-hand record is a sub-record of the left. 34 | set recordA to {name:"apple", color:"red", taste:"sweet"} 35 | set recordB to {color:"red"} 36 | set recordC to {shape:"round"} 37 | set aContainsB to recordA contains recordB -- true 38 | set aContainsC to recordA contains recordC -- false 39 | 40 | return "String: " & hasHello & ", List: " & hasBanana & ", Record: " & aContainsB 41 | ``` 42 | **Note:** When checking if a list contains a record, or vice-versa, AppleScript compares based on the structure and values. For checking if a record contains a specific *key*, you usually try to access the property in a `try` block. 43 | END_TIP 44 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/operators/core_operator_logical.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Logical Operators (and, or, not)' 3 | category: 02_as_core 4 | id: core_operator_logical 5 | description: >- 6 | Explains the logical operators 'and', 'or', and 'not' for combining boolean 7 | expressions. 8 | keywords: 9 | - operator 10 | - logical 11 | - and 12 | - or 13 | - not 14 | - boolean logic 15 | - condition 16 | language: applescript 17 | notes: Logical operators are fundamental for building complex conditional statements. 18 | --- 19 | 20 | Logical operators combine boolean values to produce a single boolean result. 21 | 22 | ```applescript 23 | set a to true 24 | set b to false 25 | set c to true 26 | 27 | -- AND operator (true if all operands are true) 28 | set result_a_and_b to a and b -- false 29 | set result_a_and_c to a and c -- true 30 | 31 | -- OR operator (true if at least one operand is true) 32 | set result_a_or_b to a or b -- true 33 | set result_b_or_false to b or false -- false 34 | 35 | -- NOT operator (reverses the boolean value) 36 | set result_not_a to not a -- false 37 | set result_not_b to not b -- true 38 | 39 | -- Combining operators (parentheses for clarity and precedence) 40 | set complexResult1 to (a and c) or b -- (true and true) or false -> true or false -> true 41 | set complexResult2 to not (b or (a and false)) -- not (false or (true and false)) -> not (false or false) -> not false -> true 42 | 43 | -- Example in an if statement 44 | set age to 25 45 | set hasLicense to true 46 | set canDrive to "Cannot Drive" 47 | 48 | if age > 18 and hasLicense then 49 | set canDrive to "Can Drive" 50 | end if 51 | 52 | if (age < 16 or not hasLicense) then 53 | -- Additional logic for very young or unlicensed 54 | end if 55 | 56 | return "a AND b: " & result_a_and_b & ¬ 57 | "\na AND c: " & result_a_and_c & ¬ 58 | "\na OR b: " & result_a_or_b & ¬ 59 | "\nNOT a: " & result_not_a & ¬ 60 | "\nComplex Result 1: " & complexResult1 & ¬ 61 | "\nCan Drive Status: " & canDrive 62 | ``` 63 | END_TIP 64 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/operators/core_operator_string_prefix_suffix.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: String Prefix/Suffix Operators' 3 | category: 02_as_core 4 | id: core_operator_string_prefix_suffix 5 | description: 'Covers string operators like ''starts with'', ''ends with'', and their negations.' 6 | keywords: 7 | - operator 8 | - string 9 | - starts with 10 | - ends with 11 | - prefix 12 | - suffix 13 | - does not start with 14 | - does not end with 15 | language: applescript 16 | notes: >- 17 | These operators are case-insensitive by default but can be made case-sensitive 18 | using a `considering case` block. 19 | --- 20 | 21 | AppleScript provides convenient operators for checking string prefixes and suffixes. 22 | 23 | ```applescript 24 | set myString to "AppleScript Language Guide" 25 | 26 | -- Basic checks 27 | set startsWithApple to myString starts with "Apple" -- true 28 | set endsWithGuide to myString ends with "Guide" -- true 29 | set startsWithScript to myString starts with "Script" -- false 30 | set endsWithLang to myString ends with "Lang" -- false 31 | 32 | -- Negations 33 | set notStartsWithX to myString does not start with "Xojo" -- true 34 | set notEndsWithY to myString does not end with "Java" -- true 35 | 36 | -- Case sensitivity 37 | set lowerString to "applescript language guide" 38 | set startsWithAppleLower to lowerString starts with "Apple" -- true (default is case-insensitive) 39 | 40 | considering case 41 | set startsWithAppleCaseSens to lowerString starts with "Apple" -- false (case-sensitive) 42 | set endsWithGuideCaseSens to lowerString ends with "guide" -- true (case-sensitive) 43 | end considering 44 | 45 | return "Starts with Apple: " & startsWithApple & ¬ 46 | "\nEnds with Guide: " & endsWithGuide & ¬ 47 | "\nNot starts with Xojo: " & notStartsWithX & ¬ 48 | "\nStarts with Apple (lower, default): " & startsWithAppleLower & ¬ 49 | "\nStarts with Apple (lower, case-sensitive): " & startsWithAppleCaseSens & ¬ 50 | "\nEnds with guide (lower, case-sensitive): " & endsWithGuideCaseSens 51 | ``` 52 | END_TIP 53 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/reference_forms/core_reference_arbitrary.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Arbitrary Element Reference Form (''some'')' 3 | category: 02_as_core 4 | id: core_reference_arbitrary 5 | description: >- 6 | Accessing an arbitrary or random element from a collection using 'some 7 | element'. 8 | keywords: 9 | - reference form 10 | - arbitrary 11 | - some 12 | - random element 13 | - any element 14 | language: applescript 15 | notes: > 16 | - `some element` (e.g., `some file`, `some item`) returns one unspecified 17 | element from the collection. 18 | 19 | - It's not guaranteed to be cryptographically random, but provides a way to 20 | pick an item without specifying which one. 21 | 22 | - If the collection is empty, attempting to get `some element` will result in 23 | an error. 24 | --- 25 | 26 | The Arbitrary Element form (`some element`) selects an unspecified item from a collection. 27 | 28 | ```applescript 29 | -- List example 30 | set myOptions to {"Option A", "Option B", "Option C", "Option D"} 31 | if (count of myOptions) > 0 then 32 | set randomOption to some item of myOptions 33 | else 34 | set randomOption to "(List is empty)" 35 | end if 36 | 37 | -- String example (less common, but works for characters/words/paragraphs) 38 | set mySentence to "Pick any word from this sentence." 39 | if mySentence is not "" then 40 | set randomWord to some word of mySentence 41 | else 42 | set randomWord to "(String is empty)" 43 | end if 44 | 45 | -- Finder example: Get some file from the Desktop 46 | set randomFileOnDesktop to "(Finder example not run by default or Desktop empty)" 47 | (* 48 | tell application "Finder" 49 | try 50 | if (count of files of desktop) > 0 then 51 | set aFile to some file of desktop 52 | set randomFileOnDesktop to name of aFile 53 | else 54 | set randomFileOnDesktop to "No files on Desktop to pick from." 55 | end if 56 | on error errMsg 57 | set randomFileOnDesktop to "Finder error: " & errMsg 58 | end try 59 | end tell 60 | *) 61 | 62 | -- Error handling for empty collection 63 | set emptyList to {} 64 | set emptyPickError to "No error yet." 65 | try 66 | set failedPick to some item of emptyList 67 | on error errMsg 68 | set emptyPickError to "Error picking from empty list: " & errMsg 69 | end try 70 | 71 | return "Random option: " & randomOption & ¬ 72 | "\nRandom word: " & randomWord & ¬ 73 | "\nRandom Desktop file: " & randomFileOnDesktop & ¬ 74 | "\nError from empty list: " & emptyPickError 75 | ``` 76 | END_TIP 77 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/reference_forms/core_reference_filter_whose.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Filter Reference Form (''whose'' / ''where'')' 3 | category: 02_as_core 4 | id: core_reference_filter_whose 5 | description: >- 6 | Selects items from a container based on a boolean condition applied to their 7 | properties. 8 | keywords: 9 | - reference form 10 | - filter 11 | - whose 12 | - where 13 | - conditional selection 14 | - query 15 | language: applescript 16 | notes: This is a very powerful way to get specific collections of items. 17 | --- 18 | 19 | ```applescript 20 | -- Example 1: Get all .txt files on the Desktop 21 | tell application "Finder" 22 | try 23 | set textFilesOnDesktop to every file of desktop whose name extension is "txt" 24 | set fileNames to {} 25 | repeat with aFile in textFilesOnDesktop 26 | set end of fileNames to name of aFile 27 | end repeat 28 | if fileNames is {} then return "No .txt files found on Desktop." 29 | return fileNames 30 | on error errMsg 31 | return "error: " & errMsg 32 | end try 33 | end tell 34 | 35 | -- Example 2: Get all visible application processes 36 | (* 37 | tell application "System Events" 38 | set visibleApps to every application process where visible is true 39 | set appNames to {} 40 | repeat with anApp in visibleApps 41 | set end of appNames to name of anApp 42 | end repeat 43 | return appNames 44 | end tell 45 | *) 46 | ``` 47 | END_TIP 48 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_beep.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: beep Command' 3 | category: 02_as_core 4 | id: osax_beep 5 | description: Plays the system alert sound. Can specify the number of beeps. 6 | keywords: 7 | - StandardAdditions 8 | - beep 9 | - alert sound 10 | - sound 11 | - notification 12 | - osax 13 | language: applescript 14 | notes: '`beep` is a simple way to provide audible feedback.' 15 | --- 16 | 17 | Plays the default system alert sound. 18 | 19 | ```applescript 20 | -- Play one beep (default) 21 | -- beep 22 | 23 | -- Play three beeps 24 | try 25 | beep 3 26 | set beepResult to "Played 3 beeps (if sound is on)." 27 | on error errMsg 28 | set beepResult to "Error beeping: " & errMsg 29 | end try 30 | 31 | -- Note: The actual sound played depends on the System Preferences > Sound > Sound Effects settings. 32 | -- This script doesn't return a value other than what's explicitly constructed here. 33 | 34 | return beepResult & " (The 'beep' command itself doesn't return a value. Commented out single beep to avoid double beeping on run if uncommented.)" 35 | ``` 36 | END_TIP 37 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_choose_application.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: choose application Command' 3 | category: 02_as_core 4 | id: osax_choose_application 5 | description: >- 6 | Displays a dialog allowing the user to select an application. Returns an alias 7 | to the chosen application. 8 | keywords: 9 | - StandardAdditions 10 | - choose application 11 | - application selection 12 | - dialog 13 | - osax 14 | language: applescript 15 | notes: > 16 | - Parameters: `with title "text"`, `with prompt "text"`, `as application 17 | bundle` (boolean, default true). 18 | 19 | - Returns an alias to the selected application bundle. 20 | 21 | - If the user cancels, an error (number -128) is raised. 22 | --- 23 | 24 | Allows the user to select an application via a standard dialog. 25 | 26 | ```applescript 27 | try 28 | set chosenAppAlias to choose application with title "Choose an Editor" with prompt "Please select your preferred text editor:" 29 | 30 | -- Get information about the chosen application 31 | tell application "Finder" 32 | set appName to name of chosenAppAlias 33 | end tell 34 | set appPath to POSIX path of chosenAppAlias 35 | 36 | set resultMessage to "You chose: " & appName & "\nPath: " & appPath 37 | 38 | -- Example: Try to get version (might fail if app not scriptable for version or not running) 39 | -- This is a more advanced step and often requires a separate tell block to the chosen app. 40 | (* 41 | try 42 | -- This is a simplified way, direct `version of chosenAppAlias` might not work. 43 | -- Typically, you would `tell application (chosenAppAlias as text)` or similar. 44 | set appIdentifier to id of application (path to chosenAppAlias) -- Get bundle ID 45 | tell application id appIdentifier 46 | set appVersion to version 47 | set resultMessage to resultMessage & "\nVersion: " & appVersion 48 | end tell 49 | on error verErr 50 | set resultMessage to resultMessage & "\nVersion: (Could not get version - " & verErr & ")" 51 | end try 52 | *) 53 | 54 | on error errMsg number errNum 55 | if errNum is -128 then 56 | set resultMessage to "User cancelled application selection." 57 | else 58 | set resultMessage to "Error (" & errNum & "): " & errMsg 59 | end if 60 | end try 61 | 62 | return resultMessage 63 | ``` 64 | END_TIP 65 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_choose_color.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: choose color Command' 3 | category: 02_as_core 4 | id: osax_choose_color 5 | description: >- 6 | Displays the standard macOS color picker dialog and returns the selected color 7 | as an RGB list. 8 | keywords: 9 | - StandardAdditions 10 | - choose color 11 | - color picker 12 | - RGB color 13 | - dialog 14 | - osax 15 | language: applescript 16 | notes: > 17 | - The `choose color` command presents the standard macOS color picker. 18 | 19 | - Returns a list of three integers representing the Red, Green, and Blue 20 | components of the selected color, each from 0 to 65535. 21 | 22 | - If the user cancels, an error (number -128) is raised. 23 | 24 | - Can optionally take a `default color` parameter with an RGB list. 25 | --- 26 | 27 | This command allows the user to select a color using the macOS color picker. 28 | 29 | ```applescript 30 | try 31 | -- Choose color with a default (e.g., a light blue) 32 | set chosenColorRGB to choose color default color {30000, 45000, 60000} -- R, G, B values (0-65535) 33 | 34 | set redValue to item 1 of chosenColorRGB 35 | set greenValue to item 2 of chosenColorRGB 36 | set blueValue to item 3 of chosenColorRGB 37 | 38 | set resultMessage to "Chosen color (RGB 0-65535): {" & redValue & ", " & greenValue & ", " & blueValue & "}" 39 | 40 | -- Convert to RGB 0-255 for common usage (approximate) 41 | set red255 to round (redValue / 65535 * 255) without rounding 42 | set green255 to round (greenValue / 65535 * 255) without rounding 43 | set blue255 to round (blueValue / 65535 * 255) without rounding 44 | 45 | set resultMessage to resultMessage & "\nApprox. RGB (0-255): {" & red255 & ", " & green255 & ", " & blue255 & "}" 46 | 47 | on error errMsg number errNum 48 | if errNum is -128 then 49 | set resultMessage to "User cancelled color selection." 50 | else 51 | set resultMessage to "Error (" & errNum & "): " & errMsg 52 | end if 53 | end try 54 | 55 | return resultMessage 56 | ``` 57 | END_TIP 58 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_choose_file.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Choose File Dialog 3 | description: Displays a file selection dialog to allow the user to select a file 4 | keywords: 5 | - file 6 | - dialog 7 | - choose file 8 | - user selection 9 | - OSAX 10 | - scripting addition 11 | language: applescript 12 | category: 02_as_core 13 | --- 14 | 15 | This script demonstrates the `choose file` scripting addition, which shows a standard file selection dialog. 16 | 17 | ```applescript 18 | -- Basic file selection 19 | set selectedFile to choose file with prompt "Please select a file" 20 | return "You selected: " & (POSIX path of selectedFile) 21 | 22 | -- More options 23 | set selectedFile to choose file with prompt "Please select a file" ¬ 24 | of type {"txt", "md", "rtf"} ¬ 25 | default location (path to desktop folder) ¬ 26 | with invisibles ¬ 27 | with multiple selections allowed 28 | 29 | -- Handle the result (may be a list if multiple selections allowed) 30 | if class of selectedFile is list then 31 | set fileList to {} 32 | repeat with oneFile in selectedFile 33 | set end of fileList to POSIX path of oneFile 34 | end repeat 35 | return "You selected multiple files: " & fileList 36 | else 37 | return "You selected: " & (POSIX path of selectedFile) 38 | end if 39 | ``` 40 | 41 | The `choose file` command supports several parameters: 42 | - `with prompt`: Customizes the dialog message 43 | - `of type`: Filters for specific file types 44 | - `default location`: Sets the initial directory 45 | - `with invisibles`: Shows hidden files 46 | - `with multiple selections allowed`: Allows selecting multiple files 47 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_choose_url.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: choose URL Command' 3 | category: 02_as_core 4 | id: osax_choose_url 5 | description: >- 6 | Displays a dialog for the user to enter or select a URL. Returns the entered 7 | URL as text. 8 | keywords: 9 | - StandardAdditions 10 | - choose URL 11 | - URL input 12 | - dialog 13 | - web address 14 | - osax 15 | language: applescript 16 | notes: > 17 | - Parameters: `with title "text"`, `showing (URL | FTP | File | All)`, `with 18 | prompt "text"`. 19 | 20 | - `showing URL` (default): Shows a field for HTTP/HTTPS URLs. 21 | 22 | - `showing FTP`: Shows fields for FTP URLs. 23 | 24 | - `showing File`: Shows a file browser to select a local file URL 25 | (`file:///...`). 26 | 27 | - `showing All`: Provides a popup to switch between URL, FTP, and File. 28 | 29 | - Returns the URL as a string (e.g., "http://www.apple.com" or 30 | "ftp://ftp.example.com" or "file:///Users/user/Desktop/file.txt"). 31 | 32 | - If the user cancels, an error (number -128) is raised. 33 | --- 34 | 35 | Allows the user to input or select a URL via a specialized dialog. 36 | 37 | ```applescript 38 | set chosenURL to "" 39 | try 40 | -- Choose a URL, showing HTTP/HTTPS field by default 41 | set urlResult to choose URL with prompt "Enter the website URL:" with title "Website Chooser" 42 | if urlResult is not false then 43 | set chosenURL to "URL: " & urlResult 44 | else 45 | set chosenURL to "User cancelled URL input." 46 | end if 47 | 48 | -- Choose a File URL 49 | set fileURLResult to choose URL showing File with prompt "Select a local file to get its URL:" with title "File URL Chooser" 50 | if fileURLResult is not false then 51 | set chosenURL to chosenURL & "\nFile URL: " & fileURLResult 52 | else 53 | set chosenURL to chosenURL & "\nUser cancelled File URL input." 54 | end if 55 | 56 | on error errMsg number errNum 57 | if errNum is -128 then 58 | set chosenURL to chosenURL & "\nUser cancelled a dialog (-128)." 59 | else 60 | set chosenURL to chosenURL & "\nError (" & errNum & "): " & errMsg 61 | end if 62 | end try 63 | 64 | return chosenURL 65 | ``` 66 | END_TIP 67 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_current_date.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: current date Command' 3 | category: 02_as_core 4 | id: osax_current_date 5 | description: Returns the current system date and time as a date object. 6 | keywords: 7 | - StandardAdditions 8 | - current date 9 | - date 10 | - time 11 | - now 12 | - timestamp 13 | - osax 14 | language: applescript 15 | notes: >- 16 | The returned value is a standard AppleScript date object, from which you can 17 | extract components like year, month, day, time string, etc. 18 | --- 19 | 20 | `current date` retrieves the system's current date and time. 21 | 22 | ```applescript 23 | set now to current date 24 | 25 | -- Extracting components 26 | set theYear to year of now 27 | set theMonth to month of now -- e.g., December (a month constant) 28 | set theDay to day of now -- e.g., 7 (an integer) 29 | set theWeekday to weekday of now -- e.g., Sunday (a weekday constant) 30 | 31 | set theHours to hours of now -- e.g., 14 (integer, 24-hour format) 32 | set theMinutes to minutes of now -- e.g., 30 (integer) 33 | set theSeconds to seconds of now -- e.g., 5 (integer) 34 | 35 | set timeStr to time string of now -- e.g., "2:30:05 PM" 36 | set dateStr to date string of now -- e.g., "Sunday, 7 July 2024" 37 | 38 | -- Coercing the full date object to a string 39 | set fullDateString to now as string -- e.g., "Sunday, 7 July 2024 at 14:30:05" 40 | 41 | return "Full Date: " & fullDateString & ¬ 42 | "\nYear: " & theYear & ¬ 43 | "\nMonth: " & (theMonth as string) & ¬ -- Coerce month constant for display 44 | "\nDay: " & theDay & ¬ 45 | "\nWeekday: " & (theWeekday as string) & ¬ -- Coerce weekday constant for display 46 | "\nTime String: " & timeStr & ¬ 47 | "\nHours: " & theHours & ":" & theMinutes & ":" & theSeconds 48 | ``` 49 | END_TIP 50 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_delay.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: delay Command' 3 | category: 02_as_core 4 | id: osax_delay 5 | description: Pauses script execution for a specified number of seconds. 6 | keywords: 7 | - StandardAdditions 8 | - delay 9 | - pause 10 | - wait 11 | - sleep 12 | - timing 13 | - osax 14 | language: applescript 15 | notes: > 16 | - The `delay` command takes a number (integer or real) representing seconds. 17 | 18 | - Fractional seconds are allowed (e.g., `delay 0.5`). 19 | 20 | - Useful for timing, waiting for UI elements to appear, or pacing script 21 | actions. 22 | --- 23 | 24 | Pauses the script for a specified duration. 25 | 26 | ```applescript 27 | log "Script started at: " & (time string of (current date)) 28 | 29 | delay 2 -- Pause for 2 seconds 30 | 31 | log "Script resumed after 2 seconds at: " & (time string of (current date)) 32 | 33 | delay 0.5 -- Pause for half a second 34 | 35 | set finalTime to time string of (current date) 36 | log "Script finished after additional 0.5s delay at: " & finalTime 37 | 38 | return "Script execution paused and resumed. Final log time: " & finalTime 39 | ``` 40 | END_TIP 41 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_do_shell_script.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: do shell script Command' 3 | category: 02_as_core 4 | id: osax_do_shell_script 5 | description: Executes a Unix shell command and returns its standard output as a string. 6 | keywords: 7 | - StandardAdditions 8 | - do shell script 9 | - terminal command 10 | - unix 11 | - bash 12 | - zsh 13 | - execute 14 | language: applescript 15 | notes: > 16 | - Always use `quoted form of` for any AppleScript variables or dynamic text 17 | passed into the shell command string to prevent errors and security issues 18 | with spaces or special characters. 19 | 20 | - When working with file paths, ALWAYS convert AppleScript paths to POSIX 21 | paths before using them with shell commands using `POSIX path of myPath`. 22 | 23 | - Never use HFS paths (colon-separated) directly in shell commands, as the 24 | shell expects POSIX paths (slash-separated). 25 | 26 | - Can use `with administrator privileges` to run as root (prompts for 27 | password). 28 | 29 | - Errors from the shell command will raise an AppleScript error. Use `try` 30 | blocks. 31 | 32 | - Environment is minimal; full paths to executables often needed. 33 | --- 34 | 35 | `do shell script` allows AppleScript to run command-line operations. 36 | 37 | ```applescript 38 | -- Simple command 39 | set whoAmI to do shell script "whoami" 40 | 41 | -- Command with arguments and variable substitution 42 | set targetFolder to POSIX path of (path to desktop) 43 | set fileList to do shell script "ls -la " & quoted form of targetFolder 44 | 45 | -- Command needing admin rights (example, use with caution) 46 | (* 47 | try 48 | do shell script "mkdir /opt/my_secure_folder" with administrator privileges 49 | set adminResult to "Created /opt/my_secure_folder with admin rights." 50 | on error adminErr 51 | set adminResult to "Admin command failed: " & adminErr 52 | end try 53 | *) 54 | 55 | return "User: " & whoAmI & "\\nDesktop Listing (first 100 chars):\\n" & (text 1 thru 100 of fileList) & "..." 56 | -- & "\\nAdmin Result: " & adminResult 57 | ``` 58 | END_TIP 59 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_info_for.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: info for Command' 3 | category: 02_as_core 4 | id: osax_info_for 5 | description: Retrieves a record of metadata about a specified file or folder alias. 6 | keywords: 7 | - StandardAdditions 8 | - info for 9 | - file metadata 10 | - folder metadata 11 | - attributes 12 | - alias 13 | language: applescript 14 | notes: > 15 | - Input must be an `alias` or `file` object. 16 | 17 | - Returns a record containing properties like name, creation date, 18 | modification date, size, kind, visible, locked, default application, etc. 19 | 20 | - File `size` is the logical size. `physical size` (if available as a separate 21 | property or via Finder) is size on disk. 22 | --- 23 | 24 | ```applescript 25 | try 26 | set targetFile to choose file with prompt "Select a file to get info for:" 27 | 28 | set fileInfo to info for targetFile 29 | 30 | set output to "File Info for: " & (name of fileInfo) & "\\n" 31 | set output to output & " Kind: " & (kind of fileInfo) & "\\n" 32 | set output to output & " Size: " & (size of fileInfo) & " bytes\\n" 33 | set output to output & " Creation Date: " & (creation date of fileInfo as string) & "\\n" 34 | set output to output & " Modification Date: " & (modification date of fileInfo as string) & "\\n" 35 | set output to output & " Visible: " & (visible of fileInfo) & "\\n" 36 | set output to output & " Locked: " & (locked of fileInfo) & "\\n" 37 | try 38 | set output to output & " Default Application: " & (POSIX path of (default application of fileInfo)) & "\\n" 39 | on error 40 | set output to output & " Default Application: Not set or not an alias\\n" 41 | end try 42 | 43 | return output 44 | 45 | on error errMsg number errNum 46 | if errNum is -128 then return "User cancelled." 47 | return "Error getting file info (" & errNum & "): " & errMsg 48 | end try 49 | ``` 50 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_path_to.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: path to Command' 3 | category: 02_as_core 4 | id: osax_path_to 5 | description: >- 6 | Returns an alias to a special system or user folder (e.g., desktop, documents, 7 | applications folder, etc.). 8 | keywords: 9 | - StandardAdditions 10 | - path to 11 | - folder path 12 | - alias 13 | - system folder 14 | - user folder 15 | language: applescript 16 | notes: > 17 | - For a full list of folder keywords, open Script Editor > File > Open 18 | Dictionary... > StandardAdditions.osax, and find the 'path to' command. 19 | 20 | - Can specify `from user domain`, `from local domain`, `from system domain`, 21 | or `from network domain`. 22 | 23 | - `as string` or `POSIX path of` can convert the returned alias to a string 24 | path. 25 | --- 26 | 27 | The `path to` command provides a reliable way to get locations of standard macOS folders. 28 | 29 | ```applescript 30 | -- Path to current user's Desktop 31 | set userDesktopAlias to path to desktop folder from user domain 32 | set userDesktopPOSIX to POSIX path of userDesktopAlias 33 | 34 | -- Path to the main Applications folder 35 | set localApplicationsAlias to path to applications folder from local domain 36 | set localApplicationsPOSIX to POSIX path of localApplicationsAlias 37 | 38 | -- Path to temporary items folder (good for temp files) 39 | set tempFolderAlias to path to temporary items from user domain 40 | set tempFolderPOSIX to POSIX path of tempFolderAlias 41 | 42 | return "User Desktop: " & userDesktopPOSIX & "\\nLocal Applications: " & localApplicationsPOSIX & "\\nTemp Folder: " & tempFolderPOSIX 43 | ``` 44 | END_TIP 45 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/scripting_additions_osax/osax_time_to_gmt.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'StandardAdditions: time to GMT Command' 3 | category: 02_as_core 4 | id: osax_time_to_gmt 5 | description: >- 6 | Returns the difference in seconds between the computer's local time zone and 7 | Greenwich Mean Time (GMT)/Coordinated Universal Time (UTC). 8 | keywords: 9 | - StandardAdditions 10 | - time to GMT 11 | - UTC offset 12 | - timezone 13 | - osax 14 | language: applescript 15 | notes: > 16 | - A negative number means local time is earlier than GMT (e.g., Americas). 17 | 18 | - A positive number means local time is later than GMT (e.g., Asia, 19 | Australia). 20 | 21 | - Result is in seconds. Divide by 3600 for hours. 22 | --- 23 | 24 | ```applescript 25 | set gmtOffsetInSeconds to time to GMT 26 | set gmtOffsetInHours to gmtOffsetInSeconds / (60 * 60) 27 | 28 | return "Offset from GMT: " & gmtOffsetInSeconds & " seconds (" & gmtOffsetInHours & " hours)." 29 | ``` 30 | END_TIP 31 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/variables_and_data_types/core_datatype_alias.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Alias Data Type' 3 | category: 02_as_core 4 | id: core_datatype_alias 5 | description: >- 6 | Working with aliases in AppleScript, which are dynamic references to file 7 | system objects. 8 | keywords: 9 | - alias 10 | - file 11 | - folder 12 | - reference 13 | - path 14 | - HFS path 15 | - data type 16 | language: applescript 17 | notes: > 18 | - An alias tracks a file or folder even if it's moved or renamed (within the 19 | same volume). 20 | 21 | - Typically represented as an HFS path string (e.g., "Macintosh 22 | HD:Users:username:Desktop:File.txt"). 23 | 24 | - Use `POSIX path of` to convert to a more portable POSIX path string. 25 | 26 | - Creating an alias to a non-existent item will result in an error. 27 | --- 28 | 29 | Aliases provide robust references to files and folders. 30 | 31 | ```applescript 32 | -- Declaration (using HFS path string) 33 | -- Note: Replace with a valid path on your system for testing 34 | -- set myFileAlias to alias "Macintosh HD:Users:yourusername:Desktop:MyTestFile.txt" 35 | -- For this example, we'll use a common existing folder 36 | set desktopAlias to path to desktop folder 37 | 38 | -- Properties 39 | set aliasName to name of desktopAlias -- e.g., "Desktop" 40 | set aliasKind to kind of desktopAlias -- e.g., "Folder" 41 | 42 | -- Coercions 43 | set hfsPathString to desktopAlias as string -- "Macintosh HD:Users:yourusername:Desktop:" 44 | set posixPathString to POSIX path of desktopAlias -- "/Users/yourusername/Desktop/" 45 | 46 | -- Using an alias with Finder (example) 47 | set itemList to "" 48 | try 49 | tell application "Finder" 50 | set itemList to name of every item of desktopAlias 51 | end tell 52 | on error 53 | set itemList to "(Could not get Finder items, ensure Finder is running)" 54 | end try 55 | 56 | -- Checking if an alias exists (it must, to be an alias, but to check a path string first) 57 | set pathToCheck to "Macintosh HD:Applications:TextEdit.app" 58 | try 59 | set appAlias to alias pathToCheck 60 | set appExists to true 61 | on error 62 | set appExists to false 63 | end try 64 | 65 | return "Alias Name: " & aliasName & "\nKind: " & aliasKind & "\nHFS Path: " & hfsPathString & "\nPOSIX Path: " & posixPathString & "\nApp Exists: " & appExists & "\nDesktop Items (first few): " & (items 1 thru (min(5, count of itemList)) of itemList as string) 66 | ``` 67 | END_TIP 68 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/variables_and_data_types/core_datatype_boolean.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Boolean Data Type' 3 | category: 02_as_core 4 | id: core_datatype_boolean 5 | description: Working with boolean (true/false) values in AppleScript. 6 | keywords: 7 | - boolean 8 | - 'true' 9 | - 'false' 10 | - data type 11 | - logical 12 | - condition 13 | language: applescript 14 | notes: | 15 | - Booleans are fundamental for conditional logic and flow control. 16 | - Result from comparisons or logical operations. 17 | --- 18 | 19 | Booleans represent logical `true` or `false` values. 20 | 21 | ```applescript 22 | -- Declaration 23 | set isReady to true 24 | set hasFailed to false 25 | 26 | -- Usage in conditions 27 | set message to "" 28 | if isReady then 29 | set message to "System is Ready." 30 | else 31 | set message to "System is not Ready." 32 | end if 33 | 34 | -- Result of comparisons 35 | set a to 10 36 | set b to 5 37 | set isGreater to a > b -- isGreater will be true 38 | 39 | -- Logical operations 40 | set bothTrue to isReady and isGreater 41 | set oneOrOtherTrue to isReady or hasFailed 42 | set isNotFailed to not hasFailed 43 | 44 | -- Coercion 45 | set boolAsString to true as string -- "true" 46 | set boolAsInteger to false as integer -- 0 (true is 1) 47 | 48 | -- Note: Strings "true" or "false" can often be coerced back, but direct comparison is safer. 49 | -- set stringAsBool to "true" as boolean -- This works 50 | 51 | return "Message: " & message & "\nIs Greater: " & isGreater & "\nBoth True: " & bothTrue & "\nNot Failed: " & isNotFailed & "\nAs String: " & boolAsString & "\nAs Integer: " & boolAsInteger 52 | ``` 53 | END_TIP 54 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/variables_and_data_types/core_datatype_date.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Date Data Type' 3 | category: 02_as_core 4 | id: core_datatype_date 5 | description: Working with dates and times in AppleScript. 6 | keywords: 7 | - date 8 | - time 9 | - data type 10 | - current date 11 | - format 12 | - calculation 13 | language: applescript 14 | notes: >- 15 | AppleScript is sensitive to date string formats. 'date "string"' is used for 16 | coercion. 17 | --- 18 | 19 | ```applescript 20 | -- Get current date and time 21 | set now to current date 22 | 23 | -- Create a specific date 24 | set specificDate to date "December 25, 2024 10:30:00 AM" 25 | 26 | -- Get parts of a date 27 | set theYear to year of now 28 | set theMonth to month of now -- returns a month constant, e.g., 'December' 29 | set theDay to day of now 30 | set theWeekday to weekday of now -- returns a weekday constant, e.g., 'Wednesday' 31 | set timeString to time string of now 32 | 33 | -- Date calculations (result is in seconds, or can be coerced back to date) 34 | set oneHourLater to now + (1 * hours) -- 'hours' is a constant 35 | set secondsDifference to specificDate - now 36 | 37 | return "Now: " & (now as string) & "\\nYear: " & theYear & "\\nOne hour later: " & (oneHourLater as string) & "\\nSeconds diff: " & secondsDifference 38 | ``` 39 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/variables_and_data_types/core_datatype_integer.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Integer Data Type' 3 | category: 02_as_core 4 | id: core_datatype_integer 5 | description: Working with integer (whole number) values in AppleScript. 6 | keywords: 7 | - integer 8 | - number 9 | - whole number 10 | - data type 11 | - math 12 | - arithmetic 13 | language: applescript 14 | notes: Integers are exact whole numbers. 15 | --- 16 | 17 | Integers are used for calculations involving whole numbers. 18 | 19 | ```applescript 20 | -- Declaration 21 | set count to 10 22 | set score to -150 23 | set quantity to 0 24 | 25 | -- Arithmetic operations 26 | set sumResult to count + 5 -- 15 27 | set diffResult to count - 3 -- 7 28 | set productResult to count * 2 -- 20 29 | set divResult to count div 3 -- 3 (integer division) 30 | set modResult to count mod 3 -- 1 (remainder) 31 | set powerResult to 2 ^ 3 -- 8 (exponentiation) 32 | 33 | -- Comparisons 34 | set isPositive to count > 0 35 | set isEqual to (score + 150) = quantity 36 | 37 | -- Coercions 38 | set intAsString to count as string -- "10" 39 | set intAsReal to count as real -- 10.0 40 | 41 | -- Coercion from string (if valid) 42 | set stringAsInt to "25" as integer 43 | 44 | return "Sum: " & sumResult & "\nDiv: " & divResult & "\nMod: " & modResult & "\nAs String: " & intAsString & "\nString as Int: " & stringAsInt 45 | ``` 46 | END_TIP 47 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/variables_and_data_types/core_datatype_list.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: List Data Type' 3 | category: 02_as_core 4 | id: core_datatype_list 5 | description: >- 6 | Working with lists (arrays) in AppleScript. Lists are 1-indexed and can 7 | contain mixed data types. 8 | keywords: 9 | - list 10 | - array 11 | - data type 12 | - item 13 | - index 14 | - count 15 | - concatenation 16 | - repeat 17 | language: applescript 18 | --- 19 | 20 | Lists are ordered collections of items. 21 | 22 | ```applescript 23 | set myList to {"apple", 123, true, {nestedList: "yes"}} 24 | 25 | -- Get count (length) 26 | set listCount to count of myList -- or length of myList 27 | 28 | -- Access items (1-indexed) 29 | set firstItem to item 1 of myList 30 | set lastItem to item -1 of myList 31 | set nestedValue to nestedList of item 4 of myList 32 | 33 | -- Add items 34 | set myList to myList & "new item" -- Concatenates, creating a new list 35 | set end of myList to "another new item" -- Modifies list in place 36 | 37 | -- Check if item exists 38 | set hasApple to "apple" is in myList 39 | 40 | -- Iterate 41 | set output to "" 42 | repeat with anItem in myList 43 | set output to output & (anItem as string) & ", " 44 | end repeat 45 | 46 | return "Count: " & listCount & "\\nFirst: " & firstItem & "\\nLast: " & lastItem & "\\nNested: " & nestedValue & "\\nHas Apple: " & hasApple & "\\nIterated: " & output 47 | ``` 48 | END_TIP 49 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/variables_and_data_types/core_datatype_record.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: Record Data Type' 3 | category: 02_as_core 4 | id: core_datatype_record 5 | description: >- 6 | Working with records (objects/dictionaries) in AppleScript, which store 7 | key-value pairs. 8 | keywords: 9 | - record 10 | - object 11 | - dictionary 12 | - data type 13 | - property 14 | - key-value 15 | language: applescript 16 | --- 17 | 18 | Records store labeled data. 19 | 20 | ```applescript 21 | set myRecord to {name:"John Doe", age:30, city:"Cupertino"} 22 | 23 | -- Access properties 24 | set personName to name of myRecord 25 | set personAge to age of myRecord 26 | 27 | -- Set properties 28 | set city of myRecord to "New York" 29 | 30 | -- Add new properties (by concatenating with another record) 31 | set myRecord to myRecord & {occupation:"Developer"} 32 | 33 | -- Check if a property exists (less direct, often involves try block or getting all properties) 34 | set propertiesList to properties of myRecord -- Not standard, better to get keys 35 | -- A way to check is: 36 | try 37 | set _ to occupation of myRecord 38 | set hasOccupation to true 39 | on error 40 | set hasOccupation to false 41 | end try 42 | 43 | return "Name: " & personName & ", Age: " & personAge & ", City: " & city of myRecord & ", Occupation: " & occupation of myRecord & ", Has Occupation: " & hasOccupation 44 | ``` 45 | END_TIP 46 | -------------------------------------------------------------------------------- /knowledge_base/02_as_core/variables_and_data_types/core_datatype_string.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Core: String Data Type' 3 | category: 02_as_core 4 | id: core_datatype_string 5 | description: >- 6 | Working with strings (text) in AppleScript, including properties like length, 7 | and elements like characters, words, paragraphs. 8 | keywords: 9 | - string 10 | - text 11 | - data type 12 | - length 13 | - character 14 | - word 15 | - paragraph 16 | - concatenation 17 | language: applescript 18 | notes: | 19 | - Strings are delimited by double quotes (`""`). 20 | - Use `&` for concatenation. 21 | - `text item delimiters` are crucial for splitting/joining strings. 22 | --- 23 | 24 | Strings are fundamental for handling text. 25 | 26 | ```applescript 27 | set myString to "Hello, AppleScript World!" 28 | 29 | -- Get length 30 | set strLength to length of myString 31 | 32 | -- Get elements 33 | set firstChar to character 1 of myString 34 | set firstWord to word 1 of myString 35 | set allWords to words of myString -- returns a list 36 | 37 | -- Concatenation 38 | set greeting to "Greetings: " & myString 39 | 40 | -- Coercion 41 | set numAsString to "123" 42 | set myNum to numAsString as integer 43 | 44 | return "Length: " & strLength & "\\nFirst Char: " & firstChar & "\\nFirst Word: " & firstWord & "\\nGreeting: " & greeting & "\\nNumber: " & myNum 45 | ``` 46 | END_TIP 47 | -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/_category_info.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "JXA Basics" 3 | description: "JavaScript for Automation (JXA) fundamentals, syntax, and examples for macOS automation using JavaScript." 4 | category: "03_jxa_core" 5 | --- 6 | 7 | This category covers JavaScript for Automation (JXA), Apple's JavaScript-based automation technology introduced in macOS Yosemite. It includes information about JXA syntax, core concepts, and how to use JavaScript to control macOS applications and system functions. JXA provides a modern alternative to AppleScript for automation while still leveraging the same underlying Apple Event architecture. -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/clipboard/jxa_clipboard_text.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: jxa_clipboard_text 3 | title: JXA Clipboard Text Operations 4 | description: Basic text operations with the clipboard using JavaScript for Automation 5 | language: javascript 6 | keywords: 7 | - clipboard 8 | - text 9 | - copy 10 | - paste 11 | - read 12 | - write 13 | category: 03_jxa_core 14 | --- 15 | 16 | # JXA Clipboard Text Operations 17 | 18 | This script provides basic text operations with the clipboard using JavaScript for Automation (JXA). 19 | 20 | ## Prerequisites 21 | 22 | First, make sure to include the Standard Additions library: 23 | 24 | ```javascript 25 | // Get the current application and include standard additions 26 | const app = Application.currentApplication(); 27 | app.includeStandardAdditions = true; 28 | ``` 29 | 30 | ## Get Text from Clipboard 31 | 32 | To read text content from the clipboard: 33 | 34 | ```javascript 35 | const app = Application.currentApplication(); 36 | app.includeStandardAdditions = true; 37 | 38 | // Get text from clipboard 39 | const clipboardText = app.theClipboard(); 40 | console.log("Clipboard contains: " + clipboardText); 41 | ``` 42 | 43 | ## Set Text to Clipboard 44 | 45 | To write text content to the clipboard: 46 | 47 | ```javascript 48 | const app = Application.currentApplication(); 49 | app.includeStandardAdditions = true; 50 | 51 | // Set text to clipboard 52 | const textToSet = "This text is now in the clipboard"; 53 | app.setTheClipboardTo(textToSet); 54 | console.log("Clipboard content set"); 55 | ``` 56 | 57 | ## Check if Clipboard Contains Text 58 | 59 | To verify if the clipboard contains text: 60 | 61 | ```javascript 62 | const app = Application.currentApplication(); 63 | app.includeStandardAdditions = true; 64 | 65 | // Try to get text from clipboard 66 | try { 67 | const clipboardText = app.theClipboard(); 68 | if (clipboardText && clipboardText.length > 0) { 69 | console.log("Clipboard contains text: " + clipboardText); 70 | } else { 71 | console.log("Clipboard is empty or doesn't contain text"); 72 | } 73 | } catch (error) { 74 | console.log("Clipboard doesn't contain text data"); 75 | } 76 | ``` 77 | 78 | These basic text operations can be used in various automation workflows to read from and write to the system clipboard. -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/jxa_browser_automation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JXA: Browser Automation' 3 | category: 03_jxa_core 4 | id: jxa_browser_automation 5 | description: >- 6 | Examples of automating Safari, Chrome, and other browsers using JXA to control 7 | tabs, perform web actions, and extract content. 8 | keywords: 9 | - jxa 10 | - javascript 11 | - safari 12 | - chrome 13 | - browser automation 14 | - web scripting 15 | - tabs 16 | - url 17 | language: javascript 18 | notes: >- 19 | Browser scripting capabilities may change with browser updates. Safari offers 20 | the most reliable automation experience on macOS. 21 | --- 22 | 23 | # Browser Automation with JXA 24 | 25 | JavaScript for Automation (JXA) provides powerful capabilities to automate and control web browsers on macOS. This document provides an overview of browser automation techniques using JXA. 26 | 27 | ## Available Scripts 28 | 29 | The following scripts provide detailed functionality for working with browsers: 30 | 31 | 1. [Safari Basic Operations](browser/jxa_safari_basic_operations.md) - Control Safari windows, tabs, and navigation 32 | 2. [Chrome Operations](browser/jxa_chrome_operations.md) - Control Google Chrome windows and tabs 33 | 3. [Safari Content Extraction](browser/jxa_safari_content_extraction.md) - Extract data from web pages using Safari 34 | 4. [Multi-browser Tab Management](browser/jxa_multi_browser_tab_management.md) - Work with tabs across multiple browsers 35 | 36 | ## Prerequisites 37 | 38 | For all browser automation scripts, it's important to have the appropriate permissions set up for your script to control browsers. Access to automation must be granted in System Settings → Privacy & Security → Automation. 39 | 40 | ## General Usage 41 | 42 | Each script provides specialized functionality and can be used independently or in combination. Refer to the individual script documentation for detailed usage instructions and examples. 43 | 44 | ## Compatibility Notes 45 | 46 | - Safari offers the most reliable automation experience on macOS 47 | - Chrome's JavaScript execution support via JXA may be limited in some versions 48 | - Browser automation capabilities may change with browser updates -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/jxa_clipboard_operations.md: -------------------------------------------------------------------------------- 1 | --- 2 | id: jxa_clipboard_operations 3 | title: Clipboard Operations with JXA 4 | description: Overview of clipboard management capabilities using JavaScript for Automation 5 | language: javascript 6 | keywords: 7 | - clipboard 8 | - copy 9 | - paste 10 | - text manipulation 11 | - file transfer 12 | category: 03_jxa_core 13 | --- 14 | 15 | # Clipboard Operations with JXA 16 | 17 | JavaScript for Automation (JXA) provides methods to read from and write to the macOS clipboard. This document provides an overview of the clipboard operations capabilities available using JXA. 18 | 19 | ## Available Scripts 20 | 21 | The following scripts provide detailed functionality for working with clipboard data: 22 | 23 | 1. [Basic Text Operations](clipboard/jxa_clipboard_text.md) - Get and set text in the clipboard 24 | 2. [Rich Text Operations](clipboard/jxa_clipboard_rich_text.md) - Work with styled RTF text 25 | 3. [Image Operations](clipboard/jxa_clipboard_images.md) - Read and write images to the clipboard 26 | 4. [File Operations](clipboard/jxa_clipboard_files.md) - Work with file paths in the clipboard 27 | 5. [Clipboard Manager](clipboard/jxa_clipboard_manager.md) - Manage multiple clipboard items 28 | 29 | ## Prerequisites 30 | 31 | For all clipboard operations, make sure to include the Standard Additions library: 32 | 33 | ```javascript 34 | // Get the current application and include standard additions 35 | const app = Application.currentApplication(); 36 | app.includeStandardAdditions = true; 37 | ``` 38 | 39 | ## General Usage 40 | 41 | Each script provides specialized functionality and can be used independently or in combination. Refer to the individual script documentation for detailed usage instructions and examples. -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/jxa_display_dialog_input.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JXA Basics: Display Dialog and Get Input' 3 | category: 03_jxa_core 4 | id: jxa_display_dialog_input 5 | description: Shows how to use 'displayDialog' in JXA to show messages and get user input. 6 | keywords: 7 | - jxa 8 | - javascript 9 | - displayDialog 10 | - dialog 11 | - user input 12 | - prompt 13 | language: javascript 14 | notes: >- 15 | `app.includeStandardAdditions = true;` is required before using 16 | `displayDialog`. 17 | --- 18 | 19 | ```javascript 20 | // JXA Script Content 21 | var app = Application.currentApplication(); 22 | app.includeStandardAdditions = true; 23 | 24 | try { 25 | var dialogResult = app.displayDialog("What is your name?", { 26 | defaultAnswer: "", 27 | buttons: ["Cancel", "OK"], 28 | defaultButton: "OK", 29 | cancelButton: "Cancel", 30 | withTitle: "JXA Input", 31 | // withIcon: Path("/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/UserInfo.icns") // Using Path object for icon 32 | }); 33 | 34 | if (dialogResult.buttonReturned === "OK") { 35 | var userName = dialogResult.textReturned; 36 | if (userName === "") { 37 | "User did not enter a name."; 38 | } else { 39 | "Hello, " + userName + "!"; 40 | } 41 | } else { 42 | "User cancelled the dialog."; 43 | } 44 | } catch (e) { 45 | // This catch block will capture errors if displayDialog itself fails, 46 | // but not user cancellation if cancelButton is defined (that's handled by buttonReturned). 47 | // If no cancelButton is specified, user cancel raises error -128. 48 | if (e.errorNumber === -128) { 49 | "User cancelled (error -128)." 50 | } else { 51 | "Error: " + e.message; 52 | } 53 | } 54 | ``` 55 | END_TIP 56 | -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/jxa_do_shell_script.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JXA: Running Shell Scripts' 3 | category: 03_jxa_core 4 | id: jxa_do_shell_script 5 | description: Shows how to execute shell commands from JXA using `app.doShellScript()`. 6 | keywords: 7 | - jxa 8 | - javascript 9 | - shell script 10 | - terminal command 11 | - execute 12 | language: javascript 13 | notes: >- 14 | `app.includeStandardAdditions = true;` is required. Paths in shell commands 15 | should be POSIX. Use `Path().toString()` or `quoted form of` for paths with 16 | spaces. 17 | --- 18 | 19 | ```javascript 20 | // JXA Script Content 21 | var app = Application.currentApplication(); 22 | app.includeStandardAdditions = true; 23 | 24 | var whoAmI = app.doShellScript("whoami"); 25 | var desktopPath = Path("~/Desktop").toString(); // Expands ~ 26 | var fileList = app.doShellScript("ls -la " +desktopPath); // Note: no 'quoted form of' in JXA directly for Path objects to shell. Better to build command carefully. 27 | 28 | // For paths with spaces, it's safer to quote them within the shell command string 29 | var folderWithSpaces = "My Folder With Spaces"; 30 | var desktopFolder = Path("~/Desktop/" + folderWithSpaces); 31 | // Create the folder if it doesn't exist for the example 32 | // app.doShellScript("mkdir -p " + desktopFolder.toString().replace(/ /g, '\\\\ ')); // Manual space escaping 33 | // A better way is to ensure the path is quoted FOR the shell 34 | var command = "ls -l " + quotedForm(desktopFolder.toString()); 35 | var listFolderWithSpaces = app.doShellScript(command); 36 | 37 | 38 | function quotedForm(s) { 39 | return "'" + s.replace(/'/g, "'\\''") + "'"; 40 | } 41 | 42 | 43 | app.displayDialog( 44 | "User: " + whoAmI + 45 | "\\n\\nDesktop List (first 100 chars):\\n" + fileList.substring(0, 100) + "..." + 46 | "\\n\\nList of '" + folderWithSpaces + "':\\n" + listFolderWithSpaces.substring(0,100) + "..." 47 | ); 48 | 49 | "Shell scripts executed."; 50 | ``` 51 | -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/jxa_file_operations.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JXA: File System Operations' 3 | category: 03_jxa_core 4 | id: jxa_file_operations 5 | description: >- 6 | Examples of file system operations in JXA, including reading, writing, and 7 | managing files and folders. 8 | keywords: 9 | - jxa 10 | - javascript 11 | - file operations 12 | - read file 13 | - write file 14 | - file system 15 | - unicode 16 | language: javascript 17 | notes: >- 18 | For Unicode support, use the Objective-C bridge approach. Standard JXA file 19 | operations are limited to ASCII. 20 | --- 21 | 22 | # File System Operations with JXA 23 | 24 | JavaScript for Automation (JXA) provides several methods for working with files and folders on macOS. This document provides an overview of file system operations using JXA. 25 | 26 | ## Available Scripts 27 | 28 | The following scripts provide detailed functionality for working with files and folders: 29 | 30 | 1. [Basic File Operations](file_operations/jxa_basic_file_operations.md) - Reading and writing files using standard JXA 31 | 2. [Unicode File Operations](file_operations/jxa_unicode_file_operations.md) - Working with Unicode text in files using the Objective-C bridge 32 | 3. [Folder Operations](file_operations/jxa_folder_operations.md) - Creating, managing, and listing folder contents 33 | 4. [File Paths and Aliases](file_operations/jxa_file_paths_and_aliases.md) - Working with different path formats and file references 34 | 35 | ## Prerequisites 36 | 37 | For all file operations, make sure to include the Standard Additions library: 38 | 39 | ```javascript 40 | // Get the current application and include standard additions 41 | const app = Application.currentApplication(); 42 | app.includeStandardAdditions = true; 43 | ``` 44 | 45 | For Unicode support and advanced file operations, you'll also need the Objective-C bridge: 46 | 47 | ```javascript 48 | // Import Foundation framework for file operations 49 | ObjC.import('Foundation'); 50 | ``` 51 | 52 | ## General Usage 53 | 54 | Each script provides specialized functionality and can be used independently or in combination. Refer to the individual script documentation for detailed usage instructions and examples. 55 | 56 | ## Important Considerations 57 | 58 | - Standard JXA file operations are limited to ASCII text 59 | - For Unicode support, use the Objective-C bridge approach 60 | - Consider using shell commands via `doShellScript()` for complex operations 61 | - File paths should be handled carefully, especially with spaces or special characters -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/jxa_finder_interaction.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JXA: Interacting with Finder' 3 | category: 03_jxa_core 4 | id: jxa_finder_interaction 5 | description: >- 6 | Demonstrates basic Finder operations like getting Desktop items and creating a 7 | folder using JXA. 8 | keywords: 9 | - jxa 10 | - javascript 11 | - finder 12 | - file system 13 | - automation 14 | language: javascript 15 | notes: >- 16 | Finder object names and properties in JXA often mirror AppleScript but use 17 | JavaScript syntax (camelCase, array indexing). 18 | --- 19 | 20 | ```javascript 21 | // JXA Script Content 22 | var Finder = Application("Finder"); 23 | Finder.includeStandardAdditions = true; // For displayDialog 24 | 25 | // Activate Finder 26 | Finder.activate(); 27 | 28 | // Get names of items on the Desktop 29 | var desktopPath = Finder.desktop.url().replace(/^file:\/\//, ''); // Get POSIX path 30 | var desktopItems = Finder.desktop.items(); // Returns an object specifier, not an array directly 31 | var itemNames = []; 32 | for (var i = 0; i < desktopItems.length; i++) { 33 | itemNames.push(desktopItems[i].name()); 34 | } 35 | 36 | // Create a new folder on the Desktop 37 | var newFolderName = "JXA Test Folder"; 38 | try { 39 | var newFolder = Finder.make({ 40 | new: 'folder', 41 | at: Finder.desktop, 42 | withProperties: { name: newFolderName } 43 | }); 44 | var creationMessage = "Folder '" + newFolderName + "' created."; 45 | } catch (e) { 46 | var creationMessage = "Folder '" + newFolderName + "' might already exist or error: " + e.message; 47 | } 48 | 49 | Finder.displayDialog( 50 | "Desktop Items (" + itemNames.length + "):\\n" + itemNames.slice(0, 5).join("\\n") + (itemNames.length > 5 ? "\\n..." : "") + 51 | "\\n\\n" + creationMessage 52 | ); 53 | 54 | "Finder interaction complete."; 55 | ``` 56 | -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/jxa_introduction_syntax.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JXA Basics: Introduction and Syntax' 3 | category: 03_jxa_core 4 | id: jxa_introduction_syntax 5 | description: >- 6 | Basic syntax for JavaScript for Automation (JXA), including how to target 7 | applications and execute commands. 8 | keywords: 9 | - jxa 10 | - javascript 11 | - automation 12 | - syntax 13 | - Application object 14 | language: javascript 15 | notes: JXA scripts are run using `osascript -l JavaScript`. 16 | --- 17 | 18 | JXA allows macOS automation using JavaScript. 19 | 20 | ```javascript 21 | // JXA Script Content 22 | 23 | // Get a reference to an application 24 | var Finder = Application("Finder"); 25 | var Safari = Application("Safari"); // Case-sensitive for app name string 26 | 27 | // Activate an application 28 | Finder.activate(); 29 | 30 | // Run a command (if app is scriptable with it) 31 | var desktopItemsCount = Finder.desktop.items.length; // Accessing properties 32 | // var frontWindow = Finder.finderWindows[0]; // JXA uses 0-based indexing for arrays 33 | 34 | // Standard Additions are available via Application.currentApplication() 35 | var app = Application.currentApplication(); 36 | app.includeStandardAdditions = true; // Important for dialogs, etc. 37 | 38 | app.displayDialog("Finder has " + desktopItemsCount + " items on the desktop."); 39 | 40 | // Return value (last expression evaluated) 41 | "JXA script executed. Desktop items: " + desktopItemsCount; 42 | ``` 43 | END_TIP 44 | -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/jxa_json_api_processing.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: JXA JSON & API Processing 3 | category: 03_jxa_core 4 | id: jxa_json_api_processing 5 | description: >- 6 | Overview of JSON processing and API integration capabilities using JavaScript for Automation (JXA). 7 | language: javascript 8 | keywords: 9 | - jxa 10 | - javascript 11 | - json 12 | - api 13 | - rest 14 | - http 15 | - fetch 16 | - process 17 | - transform 18 | - data 19 | --- 20 | 21 | # JXA JSON & API Processing 22 | 23 | This document provides an overview of the JSON processing and API integration capabilities available using JavaScript for Automation (JXA). The functionality has been split into separate, specialized scripts to make them more maintainable and easier to use. 24 | 25 | ## Available Scripts 26 | 27 | The following scripts provide detailed functionality for working with JSON data: 28 | 29 | 1. [JSON Processing Base](json_processing/jxa_json_base.md) - Core functionality and parameter handling 30 | 2. [JSON API Fetching](json_processing/jxa_json_fetch_api.md) - Fetching data from REST APIs 31 | 3. [JSON File Processing](json_processing/jxa_json_process_file.md) - Processing JSON files with transformations 32 | 4. [JSON Format Conversion](json_processing/jxa_json_convert_format.md) - Converting JSON to CSV, XML, and Property Lists 33 | 5. [JSON Data Transformation](json_processing/jxa_json_transform_data.md) - Transforming JSON with mapping, filtering, sorting, etc. 34 | 6. [JSON File Saving](json_processing/jxa_json_save_file.md) - Saving JSON data to files 35 | 7. [JSON Merging](json_processing/jxa_json_merge.md) - Merging multiple JSON sources 36 | 37 | ## General Usage 38 | 39 | Each script provides specialized functionality and can be used independently or in combination. Refer to the individual script documentation for detailed usage instructions and examples. 40 | 41 | ## Security and Networking Note 42 | 43 | When working with JSON data and APIs: 44 | 45 | 1. Data security - only transmit sensitive information over HTTPS 46 | 2. API rate limits - implement appropriate error handling and retries 47 | 3. Response validation - verify API responses before processing 48 | 4. Error handling - gracefully handle network errors and API failures 49 | 50 | When working with local files, ensure proper permissions and validation to avoid security issues. -------------------------------------------------------------------------------- /knowledge_base/03_jxa_core/jxa_ui_automation.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: JXA UI Automation 3 | category: 03_jxa_core 4 | id: jxa_ui_automation 5 | description: >- 6 | Overview of UI automation capabilities for interacting with macOS applications 7 | using JavaScript for Automation (JXA). 8 | language: javascript 9 | keywords: 10 | - jxa 11 | - javascript 12 | - automation 13 | - ui 14 | - accessibility 15 | - systemevents 16 | - click 17 | - button 18 | - interaction 19 | - form 20 | --- 21 | 22 | # JXA UI Automation 23 | 24 | This document provides an overview of UI automation capabilities using JavaScript for Automation (JXA). The functionality has been split into separate, specialized scripts for better organization and maintainability. 25 | 26 | ## Available UI Automation Scripts 27 | 28 | The following scripts provide detailed functionality for UI automation: 29 | 30 | 1. [UI Automation Base](ui_automation/jxa_ui_base.md) - Core functionality and parameter handling 31 | 2. [Click Element](ui_automation/jxa_ui_click.md) - Clicking UI elements 32 | 3. [Get & Set Values](ui_automation/jxa_ui_element_values.md) - Getting and setting values of UI elements 33 | 4. [Window Information](ui_automation/jxa_ui_window_info.md) - Getting information about application windows 34 | 5. [UI Hierarchy](ui_automation/jxa_ui_hierarchy.md) - Exploring UI element hierarchies 35 | 6. [Menu Actions](ui_automation/jxa_ui_menu_actions.md) - Performing menu actions 36 | 7. [Wait For Element](ui_automation/jxa_ui_wait_element.md) - Waiting for UI elements to appear 37 | 8. [Scroll Element](ui_automation/jxa_ui_scroll.md) - Scrolling UI elements 38 | 9. [Drag and Drop](ui_automation/jxa_ui_drag_drop.md) - Performing drag and drop operations 39 | 10. [Find UI Element](ui_automation/jxa_ui_find_element.md) - Helper for finding UI elements by various criteria 40 | 41 | ## General Usage 42 | 43 | Each script provides specialized functionality and can be used independently or in combination. Refer to the individual script documentation for detailed usage instructions and examples. 44 | 45 | ## Accessibility Requirements 46 | 47 | Note that UI automation requires appropriate accessibility permissions for your application: 48 | 49 | 1. Go to System Settings > Privacy & Security > Accessibility 50 | 2. Enable your script execution environment (e.g., Script Editor, Terminal) 51 | 52 | These scripts integrate deeply with macOS's accessibility features to provide robust UI automation capabilities beyond what traditional AppleScript can offer. -------------------------------------------------------------------------------- /knowledge_base/04_system/_category_info.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "System Interaction" 3 | description: "Scripts for interacting with macOS system features, including clipboard operations, system information, process management, and UI automation." 4 | category: "04_system" 5 | --- 6 | 7 | This category contains scripts for working with core macOS system features. It includes utilities for accessing the clipboard, retrieving system information like macOS version, managing processes, controlling system-wide UI elements, and other system-level interactions that don't fit into application-specific categories. -------------------------------------------------------------------------------- /knowledge_base/04_system/screen_lock/system_screen_lock.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: System Screen Lock 3 | category: 04_system 4 | id: system_screen_lock 5 | description: >- 6 | Locks the screen on macOS using keyboard shortcut simulation or login window 7 | accessibility 8 | keywords: 9 | - screen lock 10 | - security 11 | - login window 12 | - keyboard shortcut 13 | - System Events 14 | language: applescript 15 | notes: >- 16 | Works on macOS High Sierra (10.13) and newer. Requires accessibility 17 | permissions for System Events. 18 | --- 19 | 20 | ```applescript 21 | tell application "System Events" to keystroke "q" using {control down, command down} 22 | ``` 23 | 24 | This script locks your Mac's screen immediately by simulating the standard keyboard shortcut Control+Command+Q that Apple introduced in macOS High Sierra. 25 | 26 | For older macOS versions, you can use this alternative approach that accesses the Lock Screen option through menu navigation: 27 | 28 | ```applescript 29 | tell application "System Events" to tell process "SystemUIServer" 30 | try 31 | tell (menu bar item 1 of menu bar 1 where description is "Keychain menu extra") 32 | click 33 | click menu item "Lock Screen" of menu 1 34 | end tell 35 | on error 36 | -- Fallback to user account menu (macOS Catalina and newer) 37 | tell (menu bar item 1 of menu bar 1 where description contains "User") 38 | click 39 | click menu item "Lock Screen" of menu 1 40 | end tell 41 | end try 42 | end tell 43 | ``` 44 | 45 | This script locks the screen without suspending the machine or killing any network connections. 46 | -------------------------------------------------------------------------------- /knowledge_base/04_system/system_preferences_settings/system_settings_toggle_dark_mode.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'System Settings: Toggle Dark Mode' 3 | category: 04_system 4 | id: system_settings_toggle_dark_mode 5 | description: Toggles between light and dark mode in macOS. 6 | keywords: 7 | - dark mode 8 | - light mode 9 | - appearance 10 | - theme 11 | - System Settings 12 | language: applescript 13 | notes: Works on macOS Mojave (10.14) and later. Requires Accessibility permissions. 14 | --- 15 | 16 | ```applescript 17 | try 18 | tell application "System Events" 19 | tell appearance preferences 20 | -- Get current dark mode state 21 | set currentMode to dark mode 22 | 23 | -- Toggle dark mode 24 | set dark mode to not dark mode 25 | 26 | -- Report the change 27 | if dark mode then 28 | return "Dark mode enabled" 29 | else 30 | return "Light mode enabled" 31 | end if 32 | end tell 33 | end tell 34 | on error errMsg number errNum 35 | return "Error (" & errNum & "): Failed to toggle dark mode - " & errMsg & "\\n\\nNote: This script requires Accessibility permissions for System Events." 36 | end try 37 | ``` 38 | END_TIP 39 | -------------------------------------------------------------------------------- /knowledge_base/04_system/ui_scripting_systemwide/system_ui_click_menu_bar_item.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'System UI: Click Menu Bar Item of Frontmost App' 3 | category: 04_system 4 | id: system_ui_click_menu_bar_item 5 | description: >- 6 | Clicks a top-level menu bar item (e.g., 'File', 'Edit') of the currently 7 | frontmost application. 8 | keywords: 9 | - ui scripting 10 | - menu bar 11 | - click menu 12 | - System Events 13 | - frontmost app 14 | language: applescript 15 | isComplex: true 16 | argumentsPrompt: 'Name of the menu to click (e.g., ''File'', ''Window'') as ''menuName'' in inputData.' 17 | notes: >- 18 | Requires Accessibility permissions. The frontmost application must have the 19 | specified menu. 20 | --- 21 | 22 | ```applescript 23 | --MCP_INPUT:menuName 24 | 25 | on clickMenuBarItemOfFrontApp(theMenuName) 26 | if theMenuName is missing value or theMenuName is "" then return "error: Menu name not provided." 27 | 28 | tell application "System Events" 29 | try 30 | set frontAppProcess to first application process whose frontmost is true 31 | if frontAppProcess is missing value then return "error: Could not determine frontmost application." 32 | 33 | tell frontAppProcess 34 | if not (exists menu bar 1) then return "error: Frontmost application has no menu bar." 35 | if not (exists menu bar item theMenuName of menu bar 1) then return "error: Menu '" & theMenuName & "' not found in frontmost application." 36 | 37 | click menu bar item theMenuName of menu bar 1 38 | return "Clicked menu '" & theMenuName & "' of " & (name of frontAppProcess) & "." 39 | end tell 40 | on error errMsg 41 | return "error: Failed to click menu bar item - " & errMsg 42 | end try 43 | end tell 44 | end clickMenuBarItemOfFrontApp 45 | 46 | return my clickMenuBarItemOfFrontApp("--MCP_INPUT:menuName") 47 | ``` 48 | END_TIP 49 | -------------------------------------------------------------------------------- /knowledge_base/05_files/_category_info.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "File System and Finder" 3 | description: "Scripts for file operations, Finder interactions, paths, and file system management on macOS." 4 | category: "05_files" 5 | --- 6 | 7 | This category contains scripts for working with files, folders, and the macOS Finder. It covers both Finder-dependent operations (like getting selected items) and direct file system operations that don't require Finder (like reading and writing files). Scripts in this category also handle path conversions between different macOS path formats and file selection dialogs. -------------------------------------------------------------------------------- /knowledge_base/05_files/do_shell_script_for_files/shell_list_directory_ls.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Shell: List Directory Contents (ls -la)' 3 | category: 05_files 4 | id: shell_list_directory_ls 5 | description: >- 6 | Uses 'do shell script' with 'ls -la' to get a detailed listing of a 7 | directory's contents. 8 | keywords: 9 | - shell 10 | - ls 11 | - list directory 12 | - file listing 13 | - terminal command 14 | language: applescript 15 | isComplex: true 16 | argumentsPrompt: >- 17 | Absolute POSIX path of the directory as 'dirPath' in inputData (e.g., { 18 | "dirPath": "~/Documents" }). 19 | --- 20 | 21 | ```applescript 22 | --MCP_INPUT:dirPath 23 | 24 | on listDirectoryDetailed(posixDirPath) 25 | if posixDirPath is missing value or posixDirPath is "" then 26 | return "error: Directory path not provided." 27 | end if 28 | 29 | try 30 | -- Ensure the path is expanded (e.g. ~) and quoted for the shell 31 | set expandedPath to do shell script "echo " & quoted form of posixDirPath 32 | 33 | -- Check if directory exists 34 | set checkCmd to "test -d " & quoted form of expandedPath & " && echo 'exists' || echo 'not exists'" 35 | set dirExists to do shell script checkCmd 36 | 37 | if dirExists is "not exists" then 38 | return "error: Directory does not exist at path: " & posixDirPath 39 | end if 40 | 41 | -- Get and return directory listing 42 | return do shell script "ls -la " & quoted form of expandedPath 43 | on error errMsg 44 | return "error: Failed to list directory '" & posixDirPath & "': " & errMsg 45 | end try 46 | end listDirectoryDetailed 47 | 48 | return my listDirectoryDetailed("--MCP_INPUT:dirPath") 49 | ``` 50 | END_TIP 51 | -------------------------------------------------------------------------------- /knowledge_base/05_files/file_operations_finder/finder_create_new_folder.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Finder: Create New Folder' 3 | category: 05_files 4 | id: finder_create_new_folder 5 | description: Creates a new folder in a specified location using Finder. 6 | keywords: 7 | - Finder 8 | - new folder 9 | - create folder 10 | - directory 11 | - file management 12 | language: applescript 13 | argumentsPrompt: Enter the folder path and name for the new folder 14 | notes: >- 15 | Creates a new folder at the specified location. The parent directory must 16 | already exist. 17 | --- 18 | 19 | ```applescript 20 | on run {parentPath, folderName} 21 | try 22 | -- Handle placeholder substitution 23 | if parentPath is "" or parentPath is missing value then 24 | set parentPath to "--MCP_INPUT:parentPath" 25 | end if 26 | 27 | if folderName is "" or folderName is missing value then 28 | set folderName to "--MCP_INPUT:folderName" 29 | end if 30 | 31 | -- Verify parent path format 32 | if parentPath does not start with "/" then 33 | return "Error: Parent path must be a valid absolute POSIX path starting with /" 34 | end if 35 | 36 | -- Check if parent directory exists 37 | tell application "System Events" 38 | if not (exists folder (POSIX file parentPath as string)) then 39 | return "Error: Parent directory does not exist: " & parentPath 40 | end if 41 | end tell 42 | 43 | -- Create the new folder using Finder 44 | tell application "Finder" 45 | -- Navigate to the parent directory 46 | set parentFolder to POSIX file parentPath as alias 47 | 48 | -- Check if folder already exists 49 | if exists folder folderName of folder parentFolder then 50 | return "A folder with this name already exists: " & folderName 51 | end if 52 | 53 | -- Create the new folder 54 | set newFolder to make new folder at parentFolder with properties {name:folderName} 55 | 56 | -- Get the full path of the new folder 57 | set newFolderPath to POSIX path of (newFolder as alias) 58 | 59 | return "Successfully created new folder: " & newFolderPath 60 | end tell 61 | 62 | on error errMsg number errNum 63 | return "Error (" & errNum & "): Failed to create folder - " & errMsg 64 | end try 65 | end run 66 | ``` 67 | END_TIP 68 | -------------------------------------------------------------------------------- /knowledge_base/05_files/file_operations_finder/finder_get_selected_items_paths.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Finder: Get POSIX Path of Selected Items' 3 | category: 05_files 4 | id: finder_get_selected_items_paths 5 | description: >- 6 | Retrieves the POSIX paths of all currently selected files and folders in the 7 | frontmost Finder window. 8 | keywords: 9 | - Finder 10 | - selection 11 | - selected files 12 | - path 13 | - POSIX 14 | language: applescript 15 | notes: > 16 | - Finder must be the frontmost application with a window open and items 17 | selected. 18 | 19 | - Returns a list of POSIX paths, one per line. 20 | --- 21 | 22 | ```applescript 23 | tell application "Finder" 24 | if not running then return "error: Finder is not running." 25 | activate -- Ensure Finder is frontmost to get its selection 26 | delay 0.2 27 | try 28 | set selectedItems to selection 29 | if selectedItems is {} then 30 | return "No items selected in Finder." 31 | end if 32 | 33 | set itemPathsList to {} 34 | repeat with anItem in selectedItems 35 | set end of itemPathsList to POSIX path of (anItem as alias) 36 | end repeat 37 | 38 | set AppleScript's text item delimiters to "\\n" 39 | set pathsString to itemPathsList as string 40 | set AppleScript's text item delimiters to "" -- Reset 41 | return pathsString 42 | 43 | on error errMsg 44 | return "error: Failed to get selected Finder items - " & errMsg 45 | end try 46 | end tell 47 | ``` 48 | END_TIP 49 | -------------------------------------------------------------------------------- /knowledge_base/05_files/file_operations_finder/finder_list_desktop_files.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Finder: List Names of Files on Desktop' 3 | category: 05_files 4 | id: finder_list_desktop_files 5 | description: >- 6 | Retrieves a list of names of all files (not folders) directly on the current 7 | user's Desktop. 8 | keywords: 9 | - Finder 10 | - list files 11 | - desktop 12 | - files 13 | - names 14 | language: applescript 15 | --- 16 | 17 | ```applescript 18 | tell application "Finder" 19 | try 20 | set desktopFiles to name of every file of desktop 21 | if desktopFiles is {} then 22 | return "No files found on the Desktop." 23 | else 24 | -- AppleScript lists are returned as {item1, item2}. For text output, join them. 25 | set AppleScript's text item delimiters to "\\n" 26 | set fileListString to desktopFiles as string 27 | set AppleScript's text item delimiters to "" -- Reset 28 | return "Files on Desktop:\\n" & fileListString 29 | end if 30 | on error errMsg 31 | return "error: Could not list Desktop files - " & errMsg 32 | end try 33 | end tell 34 | ``` 35 | END_TIP 36 | -------------------------------------------------------------------------------- /knowledge_base/05_files/file_operations_no_finder/fileops_read_text_file.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'File Ops (No Finder): Read Text File Content' 3 | category: 05_files 4 | id: fileops_read_text_file 5 | description: >- 6 | Reads the entire content of a specified text file using StandardAdditions. 7 | Returns content as a string. 8 | keywords: 9 | - read file 10 | - file content 11 | - text 12 | - StandardAdditions 13 | - UTF-8 14 | language: applescript 15 | isComplex: true 16 | argumentsPrompt: Absolute POSIX path of the file to read as 'filePath' in inputData. 17 | --- 18 | 19 | ```applescript 20 | --MCP_INPUT:filePath 21 | 22 | on readFileContent(posixPath) 23 | if posixPath is missing value or posixPath is "" then 24 | return "error: File path not provided." 25 | end if 26 | 27 | try 28 | set fileAlias to POSIX file posixPath as alias 29 | set fileContent to read fileAlias as «class utf8» -- Or 'as text' for default system encoding 30 | return fileContent 31 | on error errMsg number errNum 32 | return "error: (" & errNum & ") Failed to read file '" & posixPath & "': " & errMsg 33 | end try 34 | end readFileContent 35 | 36 | return my readFileContent("--MCP_INPUT:filePath") 37 | ``` 38 | END_TIP 39 | -------------------------------------------------------------------------------- /knowledge_base/05_files/file_operations_no_finder/fileops_write_text_file.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'File Ops (No Finder): Write Text to File (Overwrite)' 3 | category: 05_files 4 | id: fileops_write_text_file 5 | description: >- 6 | Writes provided text content to a specified file, overwriting the file if it 7 | exists, or creating it if it doesn't. Uses StandardAdditions. 8 | keywords: 9 | - write file 10 | - save file 11 | - create file 12 | - overwrite 13 | - StandardAdditions 14 | language: applescript 15 | isComplex: true 16 | argumentsPrompt: >- 17 | Absolute POSIX path for the file as 'filePath', and text content as 18 | 'fileContent' in inputData. 19 | --- 20 | 21 | ```applescript 22 | --MCP_INPUT:filePath 23 | --MCP_INPUT:fileContent 24 | 25 | on writeToFile(posixPath, textContent) 26 | if posixPath is missing value or posixPath is "" then 27 | return "error: File path not provided." 28 | end if 29 | if textContent is missing value then 30 | set textContent to "" -- Write empty content if none provided 31 | end if 32 | 33 | try 34 | set fileRef to open for access (POSIX file posixPath) with write permission 35 | set eof of fileRef to 0 -- Clear file content before writing (to overwrite) 36 | write textContent to fileRef as «class utf8» 37 | close access fileRef 38 | return "Content successfully written to: " & posixPath 39 | on error errMsg number errNum 40 | -- Ensure file is closed if open attempt succeeded but write failed. 41 | try 42 | close access (POSIX file posixPath) 43 | end try 44 | return "error: (" & errNum & ") Failed to write to file '" & posixPath & "': " & errMsg 45 | end try 46 | end writeToFile 47 | 48 | return my writeToFile("--MCP_INPUT:filePath", "--MCP_INPUT:fileContent") 49 | ``` 50 | END_TIP 51 | -------------------------------------------------------------------------------- /knowledge_base/05_files/folder_operations_finder/finder_create_new_folder_desktop.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Create New Folder on Desktop 3 | description: Creates a new folder on the desktop with a specified name 4 | keywords: 5 | - Finder 6 | - folder 7 | - create 8 | - new folder 9 | - desktop 10 | - make directory 11 | language: applescript 12 | id: finder_create_new_folder_desktop 13 | argumentsPrompt: Provide a name for the new folder 14 | category: 05_files 15 | --- 16 | 17 | This script creates a new folder on the desktop with a specified name. 18 | 19 | ```applescript 20 | -- Define folder name (can be replaced with --MCP_INPUT:folderName placeholder) 21 | set folderName to "--MCP_INPUT:folderName" 22 | 23 | if folderName is missing value or folderName is "" then 24 | set folderName to "New Folder" 25 | end if 26 | 27 | tell application "Finder" 28 | -- Get reference to the desktop 29 | set desktopPath to path to desktop folder 30 | 31 | -- Create a new folder on the desktop 32 | try 33 | -- Check if folder already exists 34 | if exists folder folderName of desktopPath then 35 | return "Error: A folder named '" & folderName & "' already exists on the desktop." 36 | end if 37 | 38 | -- Create the new folder 39 | set newFolder to make new folder at desktopPath with properties {name:folderName} 40 | 41 | -- Return the path of the new folder 42 | return "Created folder: " & (POSIX path of (newFolder as alias)) 43 | on error errMsg 44 | return "Error creating folder: " & errMsg 45 | end try 46 | end tell 47 | ``` 48 | 49 | The script: 50 | 1. Takes a folder name as input (can be customized via `--MCP_INPUT:folderName`) 51 | 2. Checks if a folder with that name already exists 52 | 3. Creates the new folder on the desktop if it doesn't exist 53 | 4. Returns the path to the newly created folder or an error message 54 | 55 | END_TIP 56 | -------------------------------------------------------------------------------- /knowledge_base/05_files/paths_and_references/paths_get_standard_folders.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Paths: Get Path to Standard Folders' 3 | category: 05_files 4 | id: paths_get_standard_folders 5 | description: >- 6 | Uses AppleScript's 'path to' command to reliably get paths to standard macOS 7 | folders like Desktop, Documents, Application Support, etc., for different 8 | domains. 9 | keywords: 10 | - path to 11 | - standard folders 12 | - desktop 13 | - documents 14 | - application support 15 | - home folder 16 | - user domain 17 | language: applescript 18 | notes: > 19 | - Valid domains: `user domain`, `local domain`, `system domain`, `network 20 | domain`. 21 | 22 | - Returns an `alias` object, which can be coerced to a POSIX path string. 23 | 24 | - For a list of folder keywords, open Script Editor, then File > Open 25 | Dictionary... > StandardAdditions.osax > `path to` command. 26 | --- 27 | 28 | The `path to` command is the most reliable way to get locations of standard folders. 29 | 30 | ```applescript 31 | -- Get POSIX path to the current user's Desktop folder 32 | set desktopPathAlias to path to desktop folder from user domain 33 | set desktopPOSIX to POSIX path of desktopPathAlias 34 | 35 | -- Get POSIX path to the system-wide Application Support folder 36 | set appSupportLocalPathAlias to path to application support from local domain 37 | set appSupportLocalPOSIX to POSIX path of appSupportLocalPathAlias 38 | 39 | -- Get path to the frontmost application's bundle (if it's a standard app) 40 | try 41 | set frontAppPathAlias to path to frontmost application 42 | set frontAppPOSIX to POSIX path of frontAppPathAlias 43 | on error 44 | set frontAppPOSIX to "N/A (frontmost app might not have a standard path)" 45 | end try 46 | 47 | return "User Desktop: " & desktopPOSIX & "\\nLocal App Support: " & appSupportLocalPOSIX & "\\nFront App: " & frontAppPOSIX 48 | ``` 49 | END_TIP 50 | -------------------------------------------------------------------------------- /knowledge_base/05_files/paths_and_references/paths_posix_vs_hfs.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Paths: Understanding POSIX and HFS+ Paths' 3 | category: 05_files 4 | id: paths_posix_vs_hfs 5 | description: >- 6 | Explains the difference between POSIX (slash-separated) and HFS+ 7 | (colon-separated) paths in AppleScript and how to convert between them. 8 | keywords: 9 | - path 10 | - POSIX 11 | - HFS 12 | - colon 13 | - slash 14 | - file system 15 | - conversion 16 | language: applescript 17 | --- 18 | 19 | macOS uses POSIX paths (e.g., `/Users/yourname/Documents/file.txt`) at the Unix level. 20 | AppleScript traditionally uses HFS+ paths (e.g., `Macintosh HD:Users:yourname:Documents:file.txt`). It's crucial to convert them correctly. 21 | 22 | **Conversion:** 23 | - POSIX to AppleScript `file` object: `POSIX file "/path/to/file"` 24 | - AppleScript `file`/`alias` or HFS path string to POSIX path string: `POSIX path of anAppleScriptPathOrFileObject` 25 | 26 | ```applescript 27 | -- Example: POSIX to AppleScript file object then back to POSIX path 28 | set myPOSIXPath to "/Applications/Calculator.app" 29 | set myASFileObject to POSIX file myPOSIXPath 30 | 31 | -- myASFileObject is now something like: file "Macintosh HD:Applications:Calculator.app" 32 | -- or alias "Macintosh HD:Applications:Calculator.app" depending on context 33 | 34 | set retrievedPOSIXPath to POSIX path of myASFileObject 35 | -- retrievedPOSIXPath is now "/Applications/Calculator.app" 36 | 37 | -- Example: HFS path string to POSIX path 38 | set userName to do shell script "whoami" 39 | set myHFSPathString to "Macintosh HD:Users:" & userName & ":Desktop:" 40 | set desktopPOSIXPath to POSIX path of myHFSPathString 41 | 42 | return "AS File Object: " & (myASFileObject as text) & "\\nRetrieved POSIX: " & retrievedPOSIXPath & "\\nDesktop POSIX: " & desktopPOSIXPath 43 | ``` 44 | 45 | **Note:** When providing paths to `do shell script`, always use POSIX paths and ensure they are properly quoted using `quoted form of`. 46 | END_TIP 47 | -------------------------------------------------------------------------------- /knowledge_base/05_files/paths_and_references/paths_user_select_file_folder.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Paths: User Selects File or Folder' 3 | category: 05_files 4 | id: paths_user_select_file_folder 5 | description: >- 6 | Uses 'choose file', 'choose folder', and 'choose file name' (for saving) to 7 | get path input from the user via standard dialogs. 8 | keywords: 9 | - choose file 10 | - choose folder 11 | - choose file name 12 | - user input 13 | - dialog 14 | - path selection 15 | language: applescript 16 | notes: > 17 | - `choose file` and `choose folder` return an `alias` if an item is selected. 18 | 19 | - `choose file name` returns a `file` object (a path specification) for a new, 20 | unsaved file. 21 | 22 | - If the user cancels, an error (number -128) is generated. Use a `try` block 23 | to handle this. 24 | --- 25 | 26 | ```applescript 27 | try 28 | -- Choose an existing file 29 | set chosenFile to choose file with prompt "Please choose a file to process:" 30 | set chosenFilePath to POSIX path of chosenFile 31 | 32 | -- Choose an existing folder 33 | set chosenFolder to choose folder with prompt "Please select a destination folder:" 34 | set chosenFolderPath to POSIX path of chosenFolder 35 | 36 | -- Choose a name and location for a new file to be saved 37 | set newFileName to choose file name with prompt "Save new data as:" default name "output.txt" default location (path to desktop) 38 | set newFilePOSIXPath to POSIX path of newFileName 39 | 40 | set output to "Chosen file: " & chosenFilePath & "\\n" 41 | set output to output & "Chosen folder: " & chosenFolderPath & "\\n" 42 | set output to output & "New file location: " & newFilePOSIXPath 43 | return output 44 | 45 | on error errMsg number errNum 46 | if errNum is -128 then -- User cancelled 47 | return "User cancelled selection." 48 | else 49 | return "Error during selection: " & errMsg 50 | end if 51 | end try 52 | ``` 53 | END_TIP 54 | -------------------------------------------------------------------------------- /knowledge_base/06_terminal/_category_info.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Terminal Emulators" 3 | description: "Scripts for automating Terminal.app and other terminal emulators on macOS." 4 | category: "06_terminal" 5 | --- 6 | 7 | This category includes scripts for controlling terminal applications on macOS, including the built-in Terminal.app. It provides examples for running commands, managing tabs and windows, and executing shell scripts from AppleScript and JXA. These scripts bridge the gap between AppleScript automation and command-line operations. -------------------------------------------------------------------------------- /knowledge_base/06_terminal/terminal_app/terminal_get_tab_content.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'Terminal: Get Current Tab Content' 3 | id: terminal_get_tab_content 4 | category: 06_terminal 5 | description: >- 6 | Retrieves the full text content (scrollback history) of the currently active 7 | tab in the frontmost Terminal.app window. 8 | keywords: 9 | - Terminal.app 10 | - content 11 | - text 12 | - buffer 13 | - history 14 | - scrollback 15 | - read 16 | - get 17 | language: applescript 18 | isComplex: false 19 | --- 20 | 21 | This script fetches all the text currently displayed in the active tab of the frontmost `Terminal.app` window, including its scrollback history. 22 | 23 | **Usage:** 24 | - Useful for capturing the state of a terminal session. 25 | - Can be used to read the output of commands that have already been run. 26 | 27 | **Important Notes:** 28 | - `Terminal.app` must be running and have an active window. 29 | - The script will target the selected tab of the frontmost window. 30 | 31 | ```applescript 32 | on runWithInput(inputData, legacyArguments) 33 | tell application "Terminal" 34 | activate 35 | if not (exists window 1) then 36 | return "Error: Terminal.app has no windows open." 37 | end if 38 | 39 | try 40 | set frontWindow to window 1 41 | set currentTab to selected tab of frontWindow 42 | set tabContent to history of currentTab 43 | return tabContent 44 | on error errMsg 45 | return "Error retrieving tab content: " & errMsg 46 | end try 47 | end tell 48 | end runWithInput 49 | ``` 50 | --- 51 | -------------------------------------------------------------------------------- /knowledge_base/07_browsers/_category_info.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Web Browsers" 3 | description: "Scripts for automating Safari, Chrome, and other web browsers, including JavaScript injection and tab management." 4 | category: "07_browsers" 5 | --- 6 | 7 | This category contains scripts for controlling web browsers on macOS, with a focus on Safari and Chrome. It includes scripts for opening URLs, managing tabs, executing JavaScript within webpages, extracting information from websites, and basic browser automation. It also includes common JavaScript snippets that can be used across different browsers. -------------------------------------------------------------------------------- /knowledge_base/07_browsers/_common_browser_js_snippets/js_click_element.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JS Snippet: Click Element' 3 | category: 07_browsers 4 | id: js_click_element 5 | description: JavaScript to programmatically click an HTML element. 6 | keywords: 7 | - javascript 8 | - dom 9 | - click 10 | - interaction 11 | language: javascript 12 | notes: >- 13 | The 'element' variable must first be obtained (e.g., via getElementById or 14 | querySelector). 15 | --- 16 | 17 | This JavaScript simulates a click on a previously selected DOM element. 18 | 19 | ```javascript 20 | // Assume 'element' is a variable holding a reference to a DOM element 21 | if (element) { 22 | element.click(); 23 | } 24 | ``` 25 | END_TIP 26 | -------------------------------------------------------------------------------- /knowledge_base/07_browsers/_common_browser_js_snippets/js_extract_all_links.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JS Snippet: Extract All Links from Page' 3 | category: 07_browsers 4 | id: js_extract_all_links 5 | description: JavaScript to find all tags on a page and return their href attributes. 6 | keywords: 7 | - javascript 8 | - dom 9 | - extract links 10 | - scrape 11 | - href 12 | - anchor tags 13 | language: javascript 14 | notes: >- 15 | Returns an array of URL strings. AppleScript will receive this as a single 16 | string, often newline-separated if the JS uses `join('\n')`. 17 | --- 18 | 19 | ```javascript 20 | (() => { 21 | const links = []; 22 | const all_a_tags = document.getElementsByTagName('a'); 23 | for (let i = 0; i < all_a_tags.length; i++) { 24 | if (all_a_tags[i].href) { 25 | links.push(all_a_tags[i].href); 26 | } 27 | } 28 | return links.join('\\n'); // Join with newlines for AppleScript to parse easily 29 | })(); 30 | ``` 31 | END_TIP 32 | -------------------------------------------------------------------------------- /knowledge_base/07_browsers/_common_browser_js_snippets/js_get_element_by_id.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JS Snippet: Get Element by ID' 3 | category: 07_browsers 4 | id: js_get_element_by_id 5 | description: JavaScript to select an HTML element by its unique ID. 6 | keywords: 7 | - javascript 8 | - dom 9 | - getelementbyid 10 | - select element 11 | language: javascript 12 | notes: >- 13 | This snippet is for use inside an AppleScript browser automation command. 14 | Returns the DOM element or null. 15 | --- 16 | 17 | This JavaScript finds an element using its `id` attribute. 18 | 19 | ```javascript 20 | // Replace 'yourElementId' with the actual ID 21 | document.getElementById('yourElementId'); 22 | ``` 23 | END_TIP 24 | -------------------------------------------------------------------------------- /knowledge_base/07_browsers/_common_browser_js_snippets/js_get_page_ready_state.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JS Snippet: Get Page Ready State' 3 | category: 07_browsers 4 | id: js_get_page_ready_state 5 | description: JavaScript to check the document's loading status (readyState). 6 | keywords: 7 | - javascript 8 | - dom 9 | - pageload 10 | - readystate 11 | - loading status 12 | language: javascript 13 | notes: >- 14 | Returns 'loading', 'interactive', or 'complete'. Useful for waiting for a page 15 | to fully load. 16 | --- 17 | 18 | ```javascript 19 | document.readyState; 20 | ``` 21 | END_TIP 22 | -------------------------------------------------------------------------------- /knowledge_base/07_browsers/_common_browser_js_snippets/js_get_set_input_value.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: 'JS Snippet: Get/Set Input Field Value' 3 | category: 07_browsers 4 | id: js_get_set_input_value 5 | description: >- 6 | JavaScript to get or set the value of an HTML input field, textarea, or 7 | select. 8 | keywords: 9 | - javascript 10 | - dom 11 | - input value 12 | - form fill 13 | - textarea 14 | - select 15 | language: javascript 16 | notes: The 'inputElement' variable must hold a reference to the form field. 17 | --- 18 | 19 | **Get Value:** 20 | ```javascript 21 | // Assume 'inputElement' is a reference to an ,