Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,19 @@ Getting started
- To install/upgrade in an existing file, use `VBA-Web - Installer.xlsm`
- To start from scratch in Excel, `VBA-Web - Blank.xlsm` has everything setup and ready to go

**For Mac Users:**

If you are using Office for Mac 2016 or later, please run:

```sh
# Run this script to copy AppleScript file
chmod +x manageAppleScript.sh
# Follow the instruction to select desired application
./manageAppleScript.sh
```

**before** you use `VBA-Web - Installer.xlsm` to install `VBA-Web`

For more details see the [Wiki](https://github.com/VBA-tools/VBA-Web/wiki)

Upgrading
Expand Down
Binary file modified VBA-Web - Installer.xlsm
Binary file not shown.
200 changes: 200 additions & 0 deletions manageAppleScript.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
#!/usr/bin/env bash

# AppleScript Manager for VBA-Web
# This script manages the VBA-Web.applescript file - installing or removing it from Microsoft Office applications

# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

# Source file path
SOURCE_FILE="src/VBA-Web.applescript"

# Function to print colored output
print_message() {
local color=$1
local message=$2
echo -e "${color}${message}${NC}"
}

# Function to check if a directory exists, create if it doesn't
ensure_directory() {
local dir=$1
if [ ! -d "$dir" ]; then
print_message $YELLOW "Creating directory: $dir"
mkdir -p "$dir"
if [ $? -ne 0 ]; then
print_message $RED "Error: Failed to create directory $dir"
exit 1
fi
fi
}

# Function to check directory permissions
check_directory_permissions() {
local dir=$1
if [ ! -w "$dir" ]; then
print_message $RED "Error: No write permission for directory $dir"
exit 1
fi
}

# Function to validate user input
validate_input() {
local input=$1
case $input in
1|2|3)
return 0
;;
*)
return 1
;;
esac
}

# Function to install AppleScript for Office applications
install_applescript() {
local app_name=$1
local bundle_id=$2

print_message $BLUE "=== Install VBA-Web AppleScript for Microsoft $app_name ==="

# Check if source file exists
if [ ! -f "$SOURCE_FILE" ]; then
print_message $RED "Error: Source file $SOURCE_FILE not found!"
print_message $YELLOW "Please make sure you are running this script from the VBA-Web project root directory."
exit 1
fi

print_message $BLUE "Found source file: $SOURCE_FILE"

TARGET_DIR="$HOME/Library/Application Scripts/$bundle_id"

# Check directory permissions
check_directory_permissions "$(dirname "$TARGET_DIR")"

# Copy the file
copy_applescript "$TARGET_DIR"

print_message $GREEN ""
print_message $GREEN "Installation completed successfully!"
print_message $BLUE "VBA-Web AppleScript has been installed to: $TARGET_DIR"
print_message $YELLOW ""
print_message $YELLOW "Note: You may need to restart Microsoft Office for the changes to take effect."
}

# Function to copy the AppleScript file
copy_applescript() {
local target_dir=$1
local target_file="$target_dir/VBA-Web.applescript"

print_message $BLUE "Copying VBA-Web.applescript to $target_dir..."

# Ensure target directory exists
ensure_directory "$target_dir"

# Check directory permissions
check_directory_permissions "$target_dir"

# Copy the file
cp "$SOURCE_FILE" "$target_file"

if [ $? -eq 0 ]; then
print_message $GREEN "Successfully installed VBA-Web.applescript to $target_dir"
else
print_message $RED "Error: Failed to copy VBA-Web.applescript to $target_dir"
exit 1
fi
}

# Function to remove the AppleScript file
remove_applescript() {
local target_dir=$1
local target_file="$target_dir/VBA-Web.applescript"

print_message $BLUE "Removing VBA-Web.applescript from $target_dir..."

# Check if the file exists
if [ ! -f "$target_file" ]; then
print_message $YELLOW "VBA-Web.applescript not found in $target_dir"
return 0
fi

# Check directory permissions
check_directory_permissions "$target_dir"

# Remove the file
rm "$target_file"

if [ $? -eq 0 ]; then
print_message $GREEN "Successfully removed VBA-Web.applescript from $target_dir"
else
print_message $RED "Error: Failed to remove VBA-Web.applescript from $target_dir"
exit 1
fi
}

# Function to remove AppleScript from Office applications
remove_applescript_from_office() {
print_message $BLUE "=== Remove VBA-Web AppleScript ==="

# Remove from Excel
TARGET_DIR="$HOME/Library/Application Scripts/com.microsoft.Excel"
remove_applescript "$TARGET_DIR"

# Remove from Access
TARGET_DIR="$HOME/Library/Application Scripts/com.microsoft.Access"
remove_applescript "$TARGET_DIR"

print_message $GREEN ""
print_message $GREEN "Removal completed successfully!"
print_message $YELLOW ""
print_message $YELLOW "Note: You may need to restart Microsoft Office for the changes to take effect."
}

# Main function
main() {
print_message $BLUE "=== VBA-Web AppleScript Manager ==="

# Check if source file exists at the beginning
if [ ! -f "$SOURCE_FILE" ]; then
print_message $RED "Error: Source file $SOURCE_FILE not found!"
print_message $YELLOW "Please make sure you are running this script from the VBA-Web project root directory."
exit 1
fi

# Display main menu
echo ""
print_message $YELLOW "Please select an action:"
echo "1) Install AppleScript for Microsoft Excel"
echo "2) Install AppleScript for Microsoft Access"
echo "3) Remove AppleScript from Microsoft Excel/Access"
echo ""

# Get user choice for action
read -p "Enter your choice (1, 2, or 3): " action_choice

# Validate user input
if ! validate_input "$action_choice"; then
print_message $RED "Invalid choice. Please run the script again and select 1, 2, or 3."
exit 1
fi

case $action_choice in
1)
install_applescript "Excel" "com.microsoft.Excel"
;;
2)
install_applescript "Access" "com.microsoft.Access"
;;
3)
remove_applescript_from_office
;;
esac
}

# Run the main function
main
17 changes: 17 additions & 0 deletions src/VBA-Web.applescript
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
on FileExists(filePath)
tell application "System Events"
return (exists disk item filePath) and class of disk item filePath = file
end tell
end FileExists

on DeleteFile(filePath)
if FileExists(filePath) then
do shell script "rm " & quoted form of POSIX path of filePath
end if
end DeleteFile

on BrowseForProjectPath()
set fileTypes to {"com.microsoft.Excel.xls", "org.openxmlformats.spreadsheetml.sheet.macroenabled"}
set chosenFile to choose file of type fileTypes with prompt "Choose Project (Excel or Access)" without multiple selections allowed
return POSIX path of chosenFile
end BrowseForProjectPath