Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
odapg authored Nov 29, 2024
0 parents commit f1b8be4
Show file tree
Hide file tree
Showing 13 changed files with 567 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2024 odapg ([email protected])

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Alzibro — A simple Alfred ZIP browser

## Introduction

Alzibro in an Alfred 5 workflow that allows browsing a ZIP file without fully opening it: navigate the hierarchy and extract individual files/folders.

## Usage

* Go to the configuration window to set options,
* Use the keyword (defined in the configuration) to call the workflow and then indicate the ZIP file,
![](./pics/Capture1.png)
or:
* Apply the Universal Action 'Browse ZIP file' to a selected ZIP archive.

<center><img src="./pics/Capture2.png" width="500"><center>

then

* Navigate with ↑, ↓, ↵ (open a folder) and ⇧↵ (go backwards in the hierarchy), ![](./pics/Capture3.png)
* Possibly search by name, ![](./pics/Capture4.png)
* Unzip a particular file/folder with ⌘↵.

## Remarks

* Alzibro does not modify the ZIP file in any way,
* It tries to recover macos' metadata (tags, etc.) together with the file.
73 changes: 73 additions & 0 deletions alfred.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
import json

FOLDER_ICON = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/DocumentsFolderIcon.icns"
ALERT_ICON = "/System/Library/CoreServices/CoreTypes.bundle/Contents/Resources/AlertNoteIcon.icns"

def clean_dict(my_vars):
return {key: val for (key, val) in my_vars.items() if val is not None}

#------------------- Functions to create items in Alfred ---------------------#

def item_variables(next_directory, do_extraction=False, file_to_extract=None):

my_vars = {
"next_directory": next_directory,
"file_to_extract": file_to_extract,
"do_extraction": do_extraction,
}
return clean_dict(my_vars)

def base_item(title, subtitle, variables, icon, is_valid=True):
my_item = {
"title": title,
"subtitle": subtitle,
"variables": variables,
"valid": is_valid,
"icon": { "path": icon },
}
return my_item

def enter_mods(modifier, subtitle, variables, is_valid, my_mods=None):
if my_mods == None:
my_mods = {}
my_vars = {
"valid": is_valid,
"subtitle": subtitle,
"variables": variables
}
result = { modifier: my_vars}
my_mods.update(result)
return

def selection_error_message(comment, subcomment):
# Writes the errors appearing before/during the zip file browsing
ResultJSON= {"items": [
{"title": comment, "subtitle": subcomment, "valid": False, "icon": {"path": ALERT_ICON}}
] }
print(json.dumps(ResultJSON))
return


#-------------- Functions to pass variables after extraction ---------------#

def outcome_JSON(next_directory, comment, zip_file, to_reveal=None):

my_vars = {
"next_directory": next_directory,
"comment": comment,
"reveal": to_reveal,
"opened_zipfile": zip_file,
}
my_vars = clean_dict(my_vars)
ResultJSON= { "alfredworkflow": { "arg" : "", "variables": my_vars, } }
return ResultJSON


def alfred_error_message(comment, next_directory, zip_file):

ResultJSON = outcome_JSON(next_directory, comment, zip_file)
print(json.dumps(ResultJSON))

38 changes: 38 additions & 0 deletions alzibro_cache_cleaner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/zsh
#
cache_folder="${alfred_workflow_cache}"
cache_basename="alzibro_cache"
cache_pid_basename="cache_script.pid"
last_zip_basename="last_cached_zipfile"
cache_timeout="${alzibro_cache_timeout}"
cache_file="${cache_folder}/${cache_basename}"
cache_pid_file="${cache_folder}/${cache_pid_basename}"
cache_last_zipfile="${cache_folder}/${last_zip_basename}"

# Put the pid in cache_script.pid file
echo $$ > "$cache_pid_file"

# Set the clock
i=$cache_timeout
running=true

# Renew timeout on signal
function handle_signal() {
i=$cache_timeout
}
trap "handle_signal" USR1

# Main loop -- wait
while $running; do
sleep 10
((i -= 10))
if ((i <= 0)); then
running=false
fi
done

# Clear the cache
rm -f $cache_file
rm -f $cache_pid_file
rm -f $cache_last_zipfile

Loading

0 comments on commit f1b8be4

Please sign in to comment.