OSL ‐ File Handling - Mistium/Origin-OS GitHub Wiki
Getting Files That have been drag and dropped onto your application
The file_dropped variable is a file uuid
// detect if the file has been dropped
if file_dropped != 0 (
file "open" file_dropped
// attempt to open the file (you may need file editor/viewer permissions)
file_dropped = 0
// reset the file dropped variable so that you only run this code once a file is dropped and not repeatedly
)
if you are modifying files you will NEED to read the page linked below
Info About files structure here
New File Commands:
file "set_file" "name.type" "content"
// returns the uuid of the file
file "goto_dir" "/directory"
// slash is the user folder
file "goto_dir" "/downloads"
log listFiles()
// will throw an error if you don't have the correct perms
file "goto_dir" "Downloads"
// equivalent of `cd Downloads`
file "set_file" "new.txt" "hello world"
// makes a new file at the current directory
file "get_file" "new.txt"
log data
// reads new.txt and logs "hello world" from the data variable
file "goto_dir" ""
// equivalent of `cd` to return to home directory
Example program to list files in your downloads
file "goto_dir" "downloads"
log listFiles()
Supported File Commands:
File Management and Manipulation Commands
The following commands and file attributes facilitate file management and manipulation within the OriginOS environment, allowing users to work with files effectively:
-
Open File (
file "open"
)- Opens the selected file to be modified.
- Sets the "file" variable to the raw JSON of the current file.
- Sets the "data" variable to the data value of the open file.
- Syntax:
Examples:file "open" (file-path or file-uuid or file-name)
file "open" user_folder ++ "/Downloads/test.txt" // only open the file and do not set the file and data variable file "open" user_folder ++ "/Downloads/test.txt" "onlyaccess"
-
Open File by ID (
file "open" "id"
)- Opens a file with the specified "file-id" for modification.
- Syntax:
file "open" "id" file-id
-
Check File Existence (
file "exists"
)- Returns a boolean indicating whether a file exists and is accessible by the current program.
- Syntax:
file "exists" file-path
-
Start Default Application for File (
file "start"
)- Runs/opens the current file in its default application.
- Syntax:
file "start"
-
Render File (
file "render"
)- Renders the currently open file.
- Syntax:
You can add "interactable" at the end of this command to render it as a file instead of as an icon.file "render" size
-
Download File (
file "download"
)- Adds a file to the downloads folder.
- Syntax (v4.5.1):
file "download" "file_name.file_extension" "icon_code" "file_data" "path"
- Examples:
file "download" "test.txt" null "hello world!" user_folder ++ "/Downloads" // adds a text file to the downloads folder
-
Get File Entry (
file "get"
)- Gets a specific file entry based on the data ID.
- Syntax:
file "get" data-id
-
Set File Entry (
file "set"
)- Sets a specific file entry based on the data ID.
- Syntax:
file "set" data-id "data"
-
Right-Click Action (
rightclick
)- Represents a right-click action on a file, text, or window with specified IDs.
- Syntax:
rightclick "file/text/window" "file-id/text/window-id"
-
Install File Type (
file "install_type"
)- Adds a new file type to the OS system.
- Syntax (v4.3.7):
file "install_type" type_code file_type_icon file_type
-
Access Current File Path (
current_file_path
)- Retrieves the file path of the current window's app file.
- Usage:
current_file_path
-
Access Current File UUID (
current_file_uuid
)- Retrieves the UUID of the current file.
- Usage:
current_file_uuid
-
Closing an Opened File (
file "close"
):
- The
file "close"
command closes the currently opened file, ending the editing session and freeing up resources. - Syntax:
file "close"
- This command is useful for concluding file editing operations and ensuring proper resource management within the OriginOS environment.
1. Purpose of Setting "file" and "data" Variables:
- The "file" variable stores metadata about the opened file, accessible as an array. For instance,
file[1]
retrieves the file type, whilefile[2]
fetches the file name. Refer to the documentation link for the complete index breakdown.
2. Resetting "file_dropped" Variable:
- After processing a dropped file, resetting
file_dropped
to 0 prevents continuous execution of the file processing code every frame, ensuring it runs only once per dropped file event.
3. Handling File Paths in "file "download"":
- The
file "download"
command downloads a file to the downloads folder by default. Adding a "path" parameter allows choosing a specific destination. For example:
This command creates a text file named "test.txt" in the "system" folder.file "download" "test.txt" "" "hello, world" "origin/(A) system"
4. Rendering Files as Interactable:
- When rendering a file as interactable, users can drag it to initiate drag-and-drop actions or click to open the file.
5. Usage of "file "get"":
- The
file "get"
command sets the "data" variable to a specific index in the file data. For example:
This logs the name of the currently open file.file "get" "2" log data
6. Purpose of "rightclick" Action:
- Using the
rightclick
action allows specifying interactable objects to bring up the right-click menu for specific files, enhancing user interaction.
7. Functionality of "file "install_type"":
- The
file "install_type"
command enriches the OS system by adding new file types. It defines icons for file types, ensuring consistent representation throughout the system, and sets default applications for handling those file types. This streamlines file management and enhances user experience.